Code:
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<math.h>
using namespace std;
int main()
{
while(1)
{
cout<<"Please choose the
operation you want to practice today (+,-,/, or *): ";
char op;cin>>op;
if(!(op=='+' || op=='-' || op=='/'
|| op=='*'))//if not a valid operator
{
cout<<"Invalid operator"<<endl;break;
}
cout<<"Please enter the level
of difficult (1 and up): ";
int dif;cin>>dif;
srand(time(NULL));
int
min=pow(10,dif-1),max=pow(10,dif)-1;//generate two random numbers
in the range min and max of digit size as dif
int score=0;
int i,j;
for(i=0;i<5;i++)//5
operations
{
int val1=min +
rand() % (( max + 1 ) - min);
int val2=min +
rand() % (( max + 1 ) - min);
if(op=='/')//for
division operator if second value is zero then repeatedly generate
second number until it is not a zero
{
while(val2!=0)
{
val2=min + rand() % (( max +
1 ) - min);
}
}
int
res,ans;//res stores user's answer, ans has correct answer
for(j=0;j<3;j++)
{
cout<<"what is "<<val1<<"
"<<op<<" "<<val2<<": ";
if(op=='*')
{
ans=val1*val2;
}
else if(op=='/')
{
ans=val1/val2;
}
else if(op=='+')
{
ans=val1+val2;
}
else if(op=='-')
{
ans=val1-val2;
}
cin>>res;
if(res==ans)
{
cout<<"correct
answer"<<endl;
score++;
break;
}
else
{
cout<<"Incorrect!";
if(j==2)
cout<<endl;//try for two more times
else cout<<" Try
again"<<endl;
}
}
cout<<"score:
"<<score<<"/"<<i+1<<endl;//no of
correct/total
}
string s;
while(1)
{
cout<<"Enter continue or
quit"<<endl;cin>>s;
if(!(s=="continue" || s=="quit"))
{
cout<<"Inavlid choice, try
again!"<<endl;
}
else
{
break;
}
}
if(s=="quit") break;
}
return 0;
}
Output:

URGent /aa bcowebdav/pid-54576-dt-content-rid-241113, 1lcouses/CSO),1122 SPRING ProjectCt+ Spring2019.dc 2/6 Project Description Welcome to the Mathematics Proctice Software. s program will help...