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";}
// Multiple Choice Test for Final
#include <iostream.h>
#include <iomanip.h>
main()
{
char choice, x, Correct, Incorrect;
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";}
double percentage = (Correct/20)*100;
system ("pause");
return 0;
}
...from the looks of it, you have two variables, Incorrect and Correct. Both of them are uninitialized. For each response, you should increment one of the two to track the results. Then, you want to divide by a double so that it doesn't do integral division.
// Multiple Choice Test for Final
#include <iostream.h>
#include <iomanip.h>
main()
{
char choice, x, Correct, Incorrect;
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";}
double percentage = (Correct/20)*100;
system ("pause");
return 0;
}