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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//Global Variables
string answer_int[4],answer[4];
int total_points = 0;
void GetScore()
{
cout << "Enter your Answer for Question 1(5 points): " << endl;
cin >> answer_int[0];
cout << "Enter your answer for Question 2(5 points): " << endl;
cin >> answer_int[1];
cout << "Enter your answer for Question 3(5 points): " << endl;
cin >> answer_int[2];
cout << "Enter your answer for question 4(5 points): " << endl;
cin >> answer_int[3];
cout << "Evaluating your final score........" << endl;
cout << " " << endl;
}
int CheckAnswers(int a,int b)
{
string statement_success[4],statement_repeat[4],statement_fail[4];
statement_success[0] = "You have answered the first question correctly, +5 points for you." ;
statement_success[1] = "You have answered the second question correctly, +5 points for you." ;
statement_success[2] = "You have answered the third question correctly, +5 points for you." ;
statement_success[3] = "You have answered the fourth question correctly, +5 points for you." ;
statement_repeat[0] = "You can try again to answer the first question correctly: " ;
statement_repeat[1] = "You can try again to answer the second question correctly: " ;
statement_repeat[2] = "You can try again to answer the third question correctly: " ;
statement_repeat[3] = "You can try again to answer the fourth question correctly: " ;
statement_fail[0] = "You have answered the first question incorrectly,no + points for you." ;
statement_fail[1] = "You have answered the second question incorrectly,no + points for you." ;
statement_fail[2] = "You have answered the third question incorrectly,no + points for you." ;
statement_fail[3] = "You have answered the fourth question incorrectly,no + points for you." ;
if(answer_int[a] == answer[b] )
{
cout << statement_success[a] << endl;
total_points = total_points + 5;
}else
{
cout << statement_fail[a] << endl;
do{
cout << statement_repeat[a] << endl;
cin >> answer_int[a];
}while(!(answer_int[a] == answer[b]));
total_points = total_points + 5;
}
}
int main () {
string q_line,a_line;
ifstream myfile ("quizzquestions.txt");
if (myfile.is_open())
{
while ( getline (myfile,q_line) )
{
cout << q_line << '\n';
}
myfile.close();
}else cout << "Unable to open file";
ifstream myfile2 ("quizzanswers.txt");
if (myfile2.is_open())
{
for(int i = 0 ;i < 4 ; i++)
{
getline (myfile2,q_line);
answer[i] = q_line ;
}
//Printing out the answers for testing purposes.
cout << answer[0] << " // " << answer[1] << " // " << answer[2] << " // " << answer[3] << endl;
myfile2.close();
}else cout << "Unable to open file";
GetScore();
CheckAnswers(0,0);
CheckAnswers(1,1);
CheckAnswers(2,2);
CheckAnswers(3,3);
cout << " ==================================" << endl;
cout << " Final Score = " << total_points << " !!" << endl;
cout << " ==================================" << endl;
return 0;
}
| |