Im trying to write a program that will make a simple math quiz for students using random numbers. The program should display a menu that allows the user to choose between Addition, Subtraction, Multiplication, Division, and Modulus operations. Here is what I have so far.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` ``````#include #include #include using namespace std; int main() { char choice; int n1,n2,answer,useranswer; bool quitnow = false; srand(static_cast(time(NULL))); n1 = rand()%20+1; n2 = rand()%20+1; answer = n1 = n2; { cout << "a.Find the sum of two numbers\n"; cout << "b.Subtract two numbers\n"; cout << "m.find the product of two numbers\n"; cout << "d.Divide two numbers\n"; cout << "r. find the Modulus of two numbers\n"; cout << "q.Quit the program\n"; cin >> choice; } if(choice == "a") { cout << "what is" << n1 << "+" << n2 << "?"; cin >> useranswer; } else if (choice == "b") { cout << "what is" << n1 << "-" << n2 << "?"; cin >> useranswer; } else if (choice == "m") { cout << "what is" << n1 << "*" << n2 << "?"; cin >> useranswer; } else if(choice == "d") { cout << "what is" << n1 << "/" << n2 << "?"; cin >> useranswer; } else if(choice == "r") { cout << "what is" << n1 << "%" << n2 << "?"; cin >> useranswer; } else if (choice == "q") { quitnow = true; } return 0; }``````
Last edited on
Please use the code tags when you post code. On the right of where you enter your post, look for <>.

You haven't really been specific as to what you're stuck on.

Your do-while loop is missing the `while` statement.
 ``12345678910`` ``````do { cout << "a.Find the sum of two numbers\n"; cout << "b.Subtract two numbers\n"; cout << "m.find the product of two numbers\n"; cout << "d.Divide two numbers\n"; cout << "r. find the Modulus of two numbers\n"; cout << "q.Quit the program\n"; cin >> choice; }while( /* condition here */ );``````

Maybe take a look at a switch-statement. It will be a lot more readable that a lot of if-statements.
http://www-numi.fnal.gov/computing/minossoft/releases/R2.3/WebDocs/Companion/cxx_crib/switch.html

Hope this helps. (:
Topic archived. No new replies allowed.