In: Computer Science
hello! So I have this CIS assignment lab but when I try to make the code I don't really know where to start from. My professor is very hard and he likes to see the outcomes as they are shown in the problem. Please help me! the program should be a C++ PLS
Write a program that can be used as a math helper for an
elementary student. The program should display two random integer
numbers that are to be added, such as:
247
+ 129
-------
The program should wait for the students 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.
The program displays a menu allowing the user to select an
addition, subtraction, multiplication, or division problem. The
final selection on the menu should let the user quit the program.
After the user has finished the math problem, the program should
display the menu again. This process is repeated until the user
chooses to quit the program.
Input Validation: If the user select an item not on the menu,
display an error message and display the menu again.
Requirements:
Addition
Generate two random numbers in the range 0 - 9.
Subtraction
Generate two random numbers in the range 0 - 9.
num1 = rand() % 10;
num2 = rand() % 10;
Make sure num2 <= num1...
while (num2 > num1)
num2 = rand() % 10;
Multiplication
Generate two random numbers. The first in the range 0 - 10, the
second in the range 0 - 9.
Division
Generate a single digit divisor
num2 = rand() % 9;
Generate a num1 that is a multiple of num2 so the division has no
remainder. The num1 is never zero.
num1 = num2 * (rand() % 10 + 1);
All constant values must be declare as a constant variable. Use
the constant variable in the calculation.
Validating the selection (1 to 5). If the selection is not in the
range between 1 and 5, the program keeps asking the input until the
correct selection is entered.
Comments in your program to explain the code logic and
calculation.
Output sample:
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 1
1
+ 2
---
4
Sorry, the correct answer is 3.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 7
The valid choices are 1, 2, 3, 4, and 5. Please choose: 2
8
+ 6
---
2
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 3
9
* 4
---
36
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
8 / 2 = 4
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 4
6 / 2 = 3
Congratulations! That's right.
Menu
1. Addition problem
2. Subtraction problem
3. Multiplication problem
4. Division problem
5. Quit this program
Enter your choice (1-5): 5
"Thank you for using math helper!"
#include <iostream>
using namespace std;
int main()
{
int ch=0,n1,n2,result=0;//initialize all values
const int randdiv=10;//this is constant variable for dividing the
rand function to get values b/w 1 to 10
cout<<"1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Quit"<<endl;//menu
cin>>ch;//read one choice
while(ch!=5)//if it is 5.quit then it quits otherwise it loops
around
{
switch(ch)//passing the choice to switch to perform correct
operations
{
case 1:n1=rand()%randdiv;//generating random number for n1
n2=rand()%randdiv;//generating random number for n2
cout<<"
"<<n1<<"\n+"<<n2<<"\n-----------------"<<endl;//printing
the question to console
cin>>result;//get the answer from them
if(n1+n2==result)//check the result if we get the correct or
not
cout<<"That's correct"<<endl;//if correct print
correct
else
cout<<"Sorry!The correct answer is
"<<(n1+n2)<<endl;//if it is wrong print the correct
answer
break;
case 2:n1=rand()%randdiv;
n2=rand()%randdiv;//generating random number for n2
while(n2>n1)//we have to get the number less than n1
n2=rand()%randdiv;//so we do this until we get lesser number than
n1
cout<<"
"<<n1<<"\n-"<<n2<<"\n-----------------"<<endl;//printing
question
cin>>result;//getting answer
if(n1-n2==result)//comparing result
cout<<"That's correct"<<endl;
else
cout<<"Sorry!The correct answer is
"<<(n1-n2)<<endl;
break;
case 3:n1=rand()%randdiv;//generating random number for n1
n2=rand()%randdiv;
cout<<"
"<<n1<<"\n*"<<n2<<"\n-----------------"<<endl;//printing
question
cin>>result;//getting answer
if(n1*n2==result)//comparing result
cout<<"That's correct"<<endl;
else
cout<<"Sorry!The correct answer is
"<<(n1*n2)<<endl;
break;
case 4:n2=rand()%9;//getting random number for n2 first as a single
digit
n1=n2*(rand()%randdiv+1);//after that multiply by n2 so we leave
remainder as 0
cout<<"
"<<n1<<"\n/"<<n2<<"\n-----------------"<<endl;//printing
question to student
cin>>result;//getting the answer from student
if(n1/n2==result)//comparing result
cout<<"That's correct"<<endl;
else
cout<<"Sorry!The correct answer is
"<<(n1/n2)<<endl;
break;
default:cout<<"Wrong choice Please select
again"<<endl;//if it is other than that choice it again
prompts for input
}
cout <<
"1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Quit"
<<endl;//taking the input again for next loop
cin>>ch;
}
return 0;
}
-----------------------------------------------------------------------------------------------------------------------------------
output