## ninatech9 Newbie Poster

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
*      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

/**********************************************************************/

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;
Count ++;

{
Count++ ;
Total = Total + 10 ;
cout << "Correct!" << endl ;
}
{

cout << setw (40) << "Incorrect!" << endl;
}
for (Total = Count * 10;Count <= 10; Count++);
cout << setw (37) << Total << endl;
return 0;
}
``````

## Skeen

``````#include <cstdlib>  // Header for randomness
#include <ctime>    // Header for time (used to seed random)
#include <iostream> // Header for general IO put

using namespace std;

int main()
{
bool done=false;
while (!done)
{
srand(time(NULL)); // Seed random
while(1)
{
int Num  = rand()%10;  // Get a random number between 0 and 10
int Num2 = rand()%10;  // Get a random number between 0 and 10
cout << "Solve the following equalation:\n" << Num << " + " << Num2 << " = ";
{
cout << endl << "CORRECT! \"" << Num << " + " << Num2 << "\" is infact " << Answer << endl;
}
else
{
cout << endl << "WRONG ANSWER! The correct answer is \"" << Num << " + " << Num2 << " = " << Num+Num2 << endl;
}