#include<iostream> #include<cstdlib> #include<ctime> using namespace std; void c
ID: 3613296 • Letter: #
Question
#include<iostream>#include<cstdlib>
#include<ctime>
using namespace std;
void check_answer(int,int,int,int &score);
int main()
{
int i,answer,x,y,op,score=0;
for(i=0;i<10;i++)
{
srand(time(0));
x=rand()%10+1;
y=rand()%10+1;
op=rand()%4+1;
cout<<i+1<<")";
switch (op)
{
case 1:
{
answer=x+y;
cout<<x<<" +"<<" "<<y<<" = ";
check_answer(x,y,answer,score);
break;
}
case 2:
{
if(x<y)
{
answer=y-x;
cout<<y<<" -"<<x<<" = ";
}
else
{
answer=x-y;
cout<<x<<" -"<<y<<" = ";
}
check_answer(x,y,answer,score);
break;
}
case 3:
{
answer=x*y;
cout<<x<<" x "<<y<<" = ";
check_answer(x,y,answer,score);
break;
}
case 4:
{
if(x<y)
{
answer=y%x;
cout<<y<<" mod"<<x<<" = ";
}
else
{
answer=x-y;
cout<<x<<" mod"<<y<<" = ";
}
check_answer(x,y,answer,score);
break;
}
}
}
cout<<" score ="<<score<<endl;
return 0;
}
void check_answer(int x,int y,int answer, int &score)
{
int user_answer;
cin>>user_answer;
if(user_answer==answer)
{
cout<<"BINGO!!"<<endl;
score++;
}
else
{
cout<<"Wrong! Answer:"<<answer<<endl;
score--;
}
}
I was required to insert a timer...The arithmetic quiz keepsgenerating for 30 seconds..and display it's score in the end
thanks
Explanation / Answer
please rate - thanks changes highlighted in red #include #include #include using namespace std; void check_answer(int,int,int,int &score); int main() { time_t start, end; int i,answer,x,y,op,score=0; double diff=0; time(&start); for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.