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; 
}

How about something like this?

#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
       int CorrectAnswers=0,AnswersDone=0; 
       while(1)
           {
           if (AnswersDone==10){break;}
           int Answer=0;
           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 << " = ";
           cin >> Answer;
           if (Answer==(Num+Num2))
              {
              cout << endl << "CORRECT! \"" << Num << " + " << Num2 << "\" is infact " << Answer << endl;
              CorrectAnswers++;
              }
           else
              {
              cout << endl << "WRONG ANSWER! The correct answer is \"" << Num << " + " << Num2 << " = " << Num+Num2 << endl;
              }
           AnswersDone++;
           }
       if (CorrectAnswers==10){cout << endl << CorrectAnswers << " out of " << AnswersDone << " that's a perfect score!!" << endl;}
       if (CorrectAnswers>=6 && CorrectAnswers<10){cout << endl << CorrectAnswers << " out of " << AnswersDone << " that's pretty good!" << endl;}
       if (CorrectAnswers>=3 && CorrectAnswers<6){cout << endl << CorrectAnswers << " out of " << AnswersDone << " that's kinda bad!" << endl;}   
       if (CorrectAnswers>=0 && CorrectAnswers<3){cout << endl << CorrectAnswers << " out of " << AnswersDone << " that's sucks!" << endl;}   
       cout << endl << "Wanna try again? [0=Yes][1=No]" << endl;
       cin >> done;
       cout << endl;
       }    
    cout << "Thanks for using this program, bye!" << endl;
    system("PAUSE");   // Wait for input b4 shutting down
    return 0;          // Terminate program
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.