Need help with loops

Look at where the points are below to see where I need help.

Write a program that will help people practice addition and subtraction. The program will display the following menu in a loop:
A addition
S subtraction
Q quit
Please enter your choice:
After the user enters A (a), S (s), or Q (q) the program will generate 2 random numbers between 0 and 100 and ask the user the appropriate question:
How much is 23 + 14? or How much is 23 - 14? depending on whether they wanted to do addition or subtraction. The program will keep the user in a loop until they have answered the question correctly. After the user has answered the question correctly display a message to the user telling them they got the question right.

The loop with the menu will continue to run until the user enters Q or q.

Points:

5 points -the loop that will display the menu and repeat as long as the user doesn't enter 'Q' or 'q'.

4 points - Accepting both 'A' and 'a', 'S' and 's', and 'Q' and 'q' to run the loop.
3 points -generating the two random numbers and storing them in variables.
Did i do this right?3 points - using srand() to change the series of random numbers generated. srand() should only be called once.
How do I do this??? 2 points - using function time() to get the clock time for srand().
How do i keep it to loop? 5 points - writing the loop to compare the computer generated answer to the operation to the value entered by the user and looping as long as the computer answer does not match the user's answer.
3 points - Displaying the messages that the user answered the question incorrectly or correctly.

I have so far.
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;

int main ()
{

srand(time(NULL));


while (true)
{
cout << "A addition" << endl;
cout << "S subtraction" << endl;
cout << "Q quit" << endl;
cout << "Please enter your choice: ";

char choice;
cin >> choice;



switch(choice)
case 'A':
case 'a':
{
int num1 = rand() % 100 + 1;
cout << "How much is " << num1;

int num2 = rand() % 100 + 1;
cout << " + " << num2 << "? ";

int answer;
cin >> answer;
cin.ignore(100, 10);

int sum = num1 + num2;



if (answer == sum)
cout << "Congratulations, you got the right answer!" << endl;

else
{
cout << endl;
cout << "Sorry, that was wrong. Correct solution is" << endl;
cout << num1;
cout << " + " << num2;
cout << " = " << sum;
}

cout << endl;
}


switch(choice)
case 'S':
case 's':
{

int num1 = rand() % 100 + 1;
cout << "How much is " << num1;

int num2 = rand() % 100 + 1;
cout << " - " << num2 << "? ";


int answer;
cin >> answer;
cin.ignore(100, 10);

int sum = num1 - num2;


if (answer == sum)
cout << "Congratulations, you got the right answer!" << endl;

else
{

cout << endl;
cout << "Sorry, that was wrong. Correct solution is" << endl;
cout << num1 << " - ";
cout << num2 << " = ";
cout << sum << endl;
}
cout << endl;
}

switch(choice)
case 'Q':
case 'q':
{
return 0;
}
}
}
Topic archived. No new replies allowed.