Im writing a multiple choice test and i have the questions down but i cant get the grading done. i need to use a switch and loop still. how will i incorporate these to find the percentage score. PLEASE HELP .
cout << "Mathematics Exam: Please choose the best answer. Take your time as you will only have one chance to amswer each question.\n";
cout << "Find x.\n";
cout << "1. 10 / 2 = x \n";
cout << "A) 8\n";
cout << "B) 5\n";
cout << "C) 0\n";
cout << "D) 10\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
cout << "2. 5 / 2 = x \n";
cout << "A) 2.5555555\n";
cout << "B) 2\n";
cout << "C) 2.500000\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'C')
{cout << "Incorrect. The answer is C.\n";}
else
{cout << "Correct.\n";}
cout << "3. 9 / x = 2 \n";
cout << "A) 4.50\n";
cout << "B) 4\n";
cout << "C) 3.95\n";
cout << "D) none of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "4. x / 5 = 20 \n";
cout << "A) 100.0\n";
cout << "B) 10000 * 0.01\n";
cout << "C) 10^2\n";
cout << "D) All of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'D')
{cout << "Incorrect. The answer is D.\n";}
else
{cout << "Correct.\n";}
cout << "5. x ^ 2 = 144\n";
cout << "A) 12\n";
cout << "B) -12\n";
cout << "C) 14\n";
cout << "D) Both A and B\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'D')
{cout << "Incorrect. The answer is D.\n";}
else
{cout << "Correct.\n";}
cout << "6. 2 + (2^0) = x \n";
cout << "A) 4\n";
cout << "B) 3\n";
cout << "C) 0\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
cout << "7. 90/30 = x\n";
cout << "A) 3\n";
cout << "B) 30\n";
cout << "C) 13\n";
cout << "D) None of the above.\n";
cout << "Enter the letter of the number you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "8. 1+1 = x\n";
cout << "A) 2\n";
cout << "B) 1\n";
cout << "C) 0\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "9. (10^1099) / (1^100)\n";
cout << "A) 10332543235\n";
cout << "B) ERR: OVERFLOW\n";
cout << "C) 50000000000000000000\n";
cout << "D) 10^1099\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'D')
{cout << "Incorrect. The answer is D.\n";}
else
{cout << "Correct.\n";}
cout << "10. x! = 362880\n"; //10
cout << "A) 10\n";
cout << "B) 9\n";
cout << "C) 8\n";
cout << "D) All of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
cout << "11. 12+1 = x\n";
cout << "A) 13\n";
cout << "B) 12\n";
cout << "C) 11\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "12. 45 = 9x\n";
cout << "A) 5\n";
cout << "B) 9\n";
cout << "C) 7\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "13. 5 * (7^2) = x\n";
cout << "A) 240\n";
cout << "B) 345\n";
cout << "C) 245\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'C')
{cout << "Incorrect. The answer is C.\n";}
else
{cout << "Correct.\n";}
cout << "14. 1 * 1 = x\n";
cout << "A) 2\n";
cout << "B) 1\n";
cout << "C) 0\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
cout << "15. 18:3 = x:9\n";
cout << "A) 36\n";
cout << "B) 72\n";
cout << "C) 54\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'c')
{cout << "Incorrect. The answer is C.\n";}
else
{cout << "Correct.\n";}
cout << "16. 92+0 = x\n";
cout << "A) 92\n";
cout << "B) 90\n";
cout << "C) 0\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "17. 7^3 = x\n";
cout << "A) 288\n";
cout << "B) 343\n";
cout << "C) 340\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
cout << "18. 1 * 0.5 = x\n";
cout << "A) .05\n";
cout << "B) 0.5\n";
cout << "C) 1/2\n";
cout << "D) Both B and C\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'D')
{cout << "Incorrect. The answer is D.\n";}
else
{cout << "Correct.\n";}
cout << "19. 3! = x\n";
cout << "A) 6\n";
cout << "B) 1\n";
cout << "C) 9\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'A')
{cout << "Incorrect. The answer is A.\n";}
else
{cout << "Correct.\n";}
cout << "20. 9090909090909090 * b^0 = x\n";
cout << "A) \n";
cout << "B) 9090909090909090\n";
cout << "C) Not enough information\n";
cout << "D) None of the above\n";
cout << "Enter the letter of the answer you have chosen. ";
cin >> choice;
if (choice != 'B')
{cout << "Incorrect. The answer is B.\n";}
else
{cout << "Correct.\n";}
Hi there, Well its good that you said you will use a switch cause there are so many lines here lol. On another note I am new as well anywho you could do the following. Make a new double variable (int currentTotal;) after you make it then after each if statement you can add a code that adds its value in points (0 or 1) so if its a right answer it may say (currentTotal += 1), add this at the bottom of each case in your switches ( and or if statements) then at the end make it divide the currentTotal by totalPossible.
Hope this helps.
edit
also make it something like cout << (currentTotal/totalPossible)*100<<"%" << endl;
this will turn it into a percent, and make sure all the variables used here are doubles.
It should return something like 50.7% or something
Use an array not char. It is easier. and at the end have it say
1 2 3 4
if (choice[4] == "...")//choice correct
cout << "#4 Correct";
if (choice[4] != "...")//choice wrong
cout << "#4 Wrong";
and then at the end have it calculate the % wrong and the % right with basic math.
If this is no help I'm sorry but after all I'm only 13 and not the greatest in c++.
I have only been trying to learn c++ for 2 months now only by teaching myself and testing things.