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)
}

