Lol.
I'm messing with the function in console apps.
#include <iostream>
#include <windows.h>
using namespace std;
_inline char* NumToAnswer ( bool answer )
{
if ( answer )
return "Yes";
else
return "No";
}
#define NUM_QUESTIONS 10
int main ( )
{
char* questions[10] = {
"Do you like pie?",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10" };
char* titles[10] = {
"Pie or not to pie. . .",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10" };
bool answers[10];
bool score[10];
int totalScore;
//Ask the user every question and record their answers.
for ( int i = 0; i < NUM_QUESTIONS; i++ )
{
int messageBoxResult = MessageBoxA ( NULL, questions[i], titles[i],
MB_ICONQUESTION | MB_YESNO );
switch ( messageBoxResult )
{
case IDYES:
answers[i] = true;
break;
case IDNO:
answers[i] = false;
break;
}
}
//Print answers.
for ( int i = 0; i < NUM_QUESTIONS; i++ )
{
cout << "Answer for question " << (i+1) << ": " << NumToAnswer ( answers[i] ) << endl;
}
}
You could easily replace the //Print Answers section with something that finds what percent of the questions were answered correctly.
EDIT:
Here's the updated code for the curious.
#include <iostream>
#include <windows.h>
using namespace std;
#define YES 1
#define NO 0
#define NUM_QUESTIONS 10
//Convert answer (1 or 0) into word (Yes or No).
_inline char* AnswerToWord ( bool answer )
{
if ( answer == YES )
return "Yes";
else
return "No";
}
_inline char* CorrectAnswer ( bool answer, bool correctAnswer )
{
if ( answer == correctAnswer )
return "Correct";
else
return "Incorrect";
}
int main ( )
{
char* questions[10] = {
"Do you like pie?",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10" };
char* titles[10] = {
"Pie or not to pie. . .",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10" };
bool answers[10];
bool correctAnswers[10] = {
YES,
YES,
YES,
YES,
YES,
YES,
YES,
YES,
YES,
YES, };
int totalScore;
//Ask the user every question and record their answers.
for ( int i = 0; i < NUM_QUESTIONS; i++ )
{
int messageBoxResult = MessageBoxA ( NULL, questions[i], titles[i],
MB_ICONQUESTION | MB_YESNO );
switch ( messageBoxResult )
{
case IDYES:
answers[i] = YES;
break;
case IDNO:
answers[i] = NO;
break;
}
}
//Print answers.
for ( int i = 0; i < NUM_QUESTIONS; i++ )
{
cout << "Question " << (i+1) << ": " << CorrectAnswer ( answers[i], correctAnswers[i] ) << endl;
}
}
Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo