I forgot to paste the actual code here!..
PHP Code:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
struct qtype {
char question [80];
char answers [4][80];
char rightanswer;
};
void getquestion (qtype item[12]);
ifstream sourcefile ("quiz.txt");
char line [80];
int c;
int count = 0;
if (sourcefile.fail())
cerr << "Error opening quiz.txt...";
else
(while ! sourcefile.eof()) {
sourcefile.getline (line, sizeof(line));
strcpy (item[count].question, line);
for (c=0; c<4; c++) {
sourcefile.getline (line, sizeof(line));
strcpy (item[count].answers[c], line);
}
sourcefile.getline (line, sizeof(line));
strcpy (item[count].rightanswer, line);
count ++;
}
sourcefile.close();
return;
}
void doquiz (qtype item[12], char ans[12]) {
int count;
int c;
for (count=0; count<12; count++) {
cout << item[count].question << endl;
for (c=0; c<4; c++)
cout <<item[count].answers[c] << endl;
cout << "Your Answer: ";
cin >> ans[count];
}
return;
}
void evaluate (qtype item[12], char ans[12], int right) {
int c;
for (c=0; c<12; c++)
if ( ans[c] == item[c].rightanswer)
right++;
return;
}
void comment (int right) {
if (right == 12)
cout << "\nPerfect score, good job!";
else if (right > 8)
cout << "\nNot bad, you do know some networking.";
else if (right > 4)
cout << "\nYou need some review..";
else
cout << "\nNot good at all! You should forget about networking.";
return;
}
void main () {
qtype item [12];
char ans [12];
int rightones = 0; //the number of answers user got right
getquestion (item);
doquiz (item, ans);
evaluate (item, ans, rightones);
comment (rightones);
return;
}