Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream> #include<cstdlib>//for rand and srand #include<ctime>//for th

ID: 3533983 • Letter: #

Question

#include<iostream>
#include<cstdlib>//for rand and srand
#include<ctime>//for the time function(seed)

using namespace std;
int main()
{
   //Get the system time
   unsigned seed = time(0);
   //seed the random number generator
   srand(seed);
   int num1, num2, result=0, answer=0;
   int choice;
   //storing random numbers
   num1 = 1 + rand() % 999;//from 1 to 999
   num2 = 1 + rand() % 999;//from 1 to 999

   do{
        cout<<"what would you like to do? Please select a number: "<<endl;
        cout<<"1. Addition"<<endl;
        cout<<"2. Subtraction"<<endl;
        cout<<"3. Multiplication"<<endl;
        cout<<"4. Division"<<endl;
        cout<<"5. Quit"<<endl;
        cin >> choice;

        switch(choice)
        {
           case 1: cout << num1 << endl;
                   cout << "+" << num2 << endl;
                   cout << "_______" << endl;
                   result = num1 + num2;
                   break;
           case 2: cout << num1 << endl;
                   cout << "-" << num2 <<endl;
                   cout << "_______" << endl;
                   result = num1 - num2;
                   break;
           case 3: cout << num1 << endl;
                   cout << "*" << num2 << endl;
                   cout << "_______" << endl;
                   result = num1*num2;
                   break;
           case 4: cout << num1 << endl;
                   cout << "/" << num2 << endl;
                   cout << "_______" << endl;
                   result = num1/num2;
                   break;
           case 5: exit(0);
                   break;
           default: cout << "Error: wrong input" << endl;
                    break;
        }

        cout << "Please enter your answer" << endl;
        cin >> answer;

        if(answer == result)
        {
           cout << "     Congratulations     " << " you got the right answer " << endl;
        }
        else
        {
           cout << " Correct answer is " << result << endl;
        }
   }while(choice !=0);
  
   system("pause");
   return 0;
}


Please help it suppose to quit when it get the wrong output and go back to the the menu and it does not do that and also I get a warning that said

Warning    1    warning C4244: 'initializing' : conversion from 'time_t' to 'unsigned int', possible loss of data    c:userscc0420documentsmy projectsmathtutormathtutormathtutor.cpp    14


Explanation / Answer

Change your srand to srand((unsigned)time(NULL)) instead of using a time_t value like you have. For your menu fix you have to move your do loop upwards. Or you can do it with a if statement after the switch. If(choice < 1 || choice > 6) continue; that'll throw the loop back to the beginning of the do while.