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

Write a C++ program that can be used as a math tutor for a young student. The pr

ID: 3666024 • Letter: W

Question

Write a C++ program that can be used as a math tutor for a young student. The program should display two random numbers to be added or subtracted, such as

247

+ 129

------------

or

56

- 867

-----------

The program should choose randomly whether the problem is addition or subtraction. The program should wait for the student to enter the answer. If the answer is correct, a message of congratulations should be printed. If the answer is incorrect, a message should be printed showing the correct answer. Make sure the numeric terms are right-aligned, even if they have different numbers of digits

Explanation / Answer

#include<iostream>
#include<stdlib.h>
using namespace std;

int main(){
  
   // generating two numbers in integer range
   srand(time(NULL));
   int num1 = rand()/32767;
   int num2 = rand()/32767;

   cout<<"First Number : "<<num1<<endl;
   cout<<"Second Number : "<<num2<<endl;
  
   cout<<"Enter your result: ";
   int userResult;
   cin>>userResult;
  
   //generating 0 or 1 randomly-- 0 means subtraction, 1 means addition
   srand( time(NULL) );
   int randNum = rand() % 2; // Generate a random number between 0 and 1
  
   int myResult;
   if(randNum == 0)
       myResult = num1 + num2;
   else
       myResult = num1 + num2;
  
   if(myResult == userResult)
       cout<<"congratulation!!!";
   else
       cout<<"Incorrect gusse, correct answer is: "<<myResult<<endl;
  
   return 0;
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote