Hi, this is one of my hw problems for the week and having trouble writing this code.--
QUESTION:
1. Create a program that will generate a 10 question math quiz for single digit addition. Your program should create 2 random numbers in the range of 0 – 9 and then ask the user to solve the equation. Let the user know if they answered correctly or not. If not, show them what the correct answer is. After the user has answered 10 questions, display the score as a percentage out of 100. Your program should allow the user to take as many 10 question exams as he wants.
The code ive writtin i was testing things with the varibles to do random 1-10 numbers, (teacher took 2 min to explain). My code is most defiently sloppy but im working hard on it.
/**********************************************************************
*Program Description: program that will generate a 10 question math
* quiz for single digit addition.
*BEGIN Program 2 - Math Quiz
* Create two random numbers of range 0-9 in addition form
* Ask user to solve equation
* WHILE User asnwers each question
* Add 1 to count
* Add 10 to total if correct answer
* IF Wrong answer display wronge answer message go to next.
* Display correct answer
* ELSE if answer right display correct answer go to next
* Stop if count == 10
* END WHILE
* Display Total in percent form
*END Program 2 - Math quiz
*********************************************************************/
#include <ctime>
#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//Local constants
int Count = 0; //Total questions
int Total = 0; //Percentage score
//Local variables
int Num1 = rand() % 10; //Random number 1-10
int Num2 = rand() % 10; //Random number 1-10
int Num3 = rand() % 10; //Random number 1-10
int Num4 = rand() % 10; //Random number 1-10
int Num5 = rand() % 10; //Random number 1-10
int Num6 = rand() % 10; //Random number 1-10
int Num7 = rand() % 10; //Random number 1-10
int Num8 = rand() % 10; //Random number 1-10
int Num9 = rand() % 10; //Random number 1-10
int Num10 = rand() % 10; //Random number 1-10
int Num11 = rand() % 10; //Random number 1-10
int Num12 = rand() % 10; //Random number 1-10
int Num13 = rand() % 10; //Random number 1-10
int Num14 = rand() % 10; //Random number 1-10
int Num15 = rand() % 10; //Random number 1-10
int Num16 = rand() % 10; //Random number 1-10
int Num17 = rand() % 10; //Random number 1-10
int Num18 = rand() % 10; //Random number 1-10
int Num19 = rand() % 10; //Random number 1-10
int Num20 = rand() % 10; //Random number 1-10
int Correct = Num1 + Num2 ;
//Reference
int Answer ;
/**********************************************************************/
srand(time(NULL));
cout << "\n\n\n\n\n\n";
cout << setw (40) << "Math Quiz" << endl ;
//While Count is less then ten
while (Count <= 10)
cout << rand() % 10 + rand() % 10 << endl;
cin >> Answer ;
Count ++;
if (Answer == Correct)
{
Count++ ;
Total = Total + 10 ;
cout << "Correct!" << endl ;
}
else (Answer != Correct);
{
cout << setw (40) << "Incorrect!" << endl;
}
//For grade
for (Total = Count * 10;Count <= 10; Count++);
cout << setw (37) << Total << endl;
return 0;
}