1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream> // cout
#include <conio.h> // _kbhit()
using namespace std;
void getAnswers( int questionNumber, char &ans1, char &ans2, char &ans3 )
{
switch( questionNumber )
{
case 1:
/* if it's question 1 you want the answers for... */
ans1 = 'a';
ans2 = 'c';
ans3 = 'e';
break;
case 2:
break;
case 3:
break;
case 4:
break;
}
}
int main()
{
char userAns1, userAns2, userAns3,
ans1, ans2, ans3;
/* output question */
/* get the answers */
//the values of ans1, ans2 and ans3 will change to the values
//within the getAnswers function, as they were passed bt reference
getAnswers( 1, ans1, ans2, ans3 );
cin >> userAns1 >> userAns2 >> userAns3;
//if you only have one statement under an if/loop, you don't need the curly braces {}
if( ( userAns1 == ans1 ) && ( userAns2 == ans2 ) && ( userAns3 == ans3 ) )
cout << "Correct answer!";
else
cout << "Incorrect!";
//press any key to exit...
std::cout << "\n\nPress any key to exit...";
while( ! _kbhit() )
{ /* do nothing - wait for key press */ }
return 0;
}
|