Page 1 of 1

C++ Assignment 6.3

Posted: Mon Oct 22, 2007 12:54 am
by vinyard
Here is assignment 6.3:

Code: Select all

/**Assignment 6.3**********
***Code by: David Rivera***
***10.22.2007*************/

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
using std::string;

bool validateInput(char i);

int main()
{
    char response;                                                                                      //create char response
    bool valid = false;                                                                                 //create boolean valid, set to fasle
    cout << "Please enter one of the following choices." << endl;                                       //output
    cout << "m) Motherboard          c) CPU" << endl;                                                   //the
    cout << "g) GPU                  h) Hard Drive" << endl;                                            //menu
    cout << "i) I hate computers." << endl;                                                             //to screen
    
    /* Loop here until the response in valid */
    do
    {
         cin >> response;
         cout << endl;
         valid = validateInput(response);
    } while(!valid);
    
    system("pause");                                                                                    //wait for user input
    return 0;
}

/* unser input validation function */
bool validateInput(char i)                                                                
{
       bool valid = false;                                                                              //create booloean valid, set to false
       switch(i)
       {
                case 'm':                                                                               //if user input matches 'm'
                     cout << "This is the main board of a computer." << endl;                           //output definition
                     valid = true;                                                                      //cahracter is valid, valid = true
                     break;
                case 'c':
                     cout << "The CPU is the brains of the computer." << endl;
                     valid = true;
                     break;
                case 'g':
                     cout << "The GPU is a dedicated graphics rendering device." << endl;
                     valid = true;
                     break;
                case 'h':
                     cout << "A Hard Disk Drive is a non-volatile storage device"
                          << " which stores digitally encoded data." << endl;
                     valid = true;
                     break;
                case 'i':
                     cout << "You Sir/ma'am are dumb." << endl;
                     valid = true;
                     break;
                default:                                                                                //user input does not match
                     cout << "Please slelect m, c, g, h or i: ";                                        //promt for a valid character
       }
       return valid;                                                                                    //return valid )true or false)
} 
Here is a SS of the output.
Assignment 6.3 (10.22.2007)
Assignment 6.3 (10.22.2007)
6_3.jpg (28.52 KiB) Viewed 977 times

Re: C++ Assignment 6.3

Posted: Thu Oct 25, 2007 11:20 am
by zero86ea
niiiice vin!

Re: C++ Assignment 6.3

Posted: Thu Oct 25, 2007 3:46 pm
by skaterbasist
Interesting to see that the switch is almost exactly how we use it in Java. Just shows how if you learn one language, you can easily learn another!

.

Re: C++ Assignment 6.3

Posted: Thu Oct 25, 2007 3:53 pm
by zero86ea
skaterbasist wrote:Interesting to see that the switch is almost exactly how we use it in Java. Just shows how if you learn one language, you can easily learn another!

.
true!