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

In this assignment, you play with variables, arithmeticoperators and random numb

ID: 3616971 • Letter: I

Question

In this assignment, you play with variables, arithmeticoperators and random numbers.

You should set up your program to use input, output, and randomnumbers. Give a short introduction and then start the programby selecting two random numbers and show them with as an additionproblem

3 + 7 =

Then ask the user to input an answer, and then display theanswer. Then do the same with subtraction, multiplication, anddivision. Don’t worry yet about whether the user got thecorrect answer yet.   Each problem should have 2 randomnumbers to add or subtract. Be sure to set your random numberin such a way that you will not get a 0 for division. Divisionby 0 would be bad.

Explanation / Answer


#include<iostream> using namespacestd; intmain() {intnum1,num2,max,count=0; doubleans; srand(time(0)); cout<<"Thisis a math practice program "; cout<<"Whatis the largest number you want your practice problems to have?"; cin>>max; cout<<"Enteryour answers after each problem "; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" + "<<num2<<" ="; cin>>ans; if(ans==(num1+num2)) cout<<"congratualions you win" break; else { cout<<"Wronganswer: try again"; count++; } } count=0; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" - "<<num2<<" ="; cin>>ans; if(ans==(num1-num2)) cout<<"congratualions you win" break; else { cout<<"Wronganswer: try again"; count++; } } count=0; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" * "<<num2<<" ="; cin>>ans; if(ans==(num1*num2)) cout<<" congratualions youwin" break; else { cout<<" Wrong answer: tryagain"; count++; } }
count=0; num1=rand()%(max+1); num2=((rand()%max)+1); while(count<3) { cout<<num1<<" / "<<num2<<" ="; cin>>ans; intresult=(int)(num1/num2); if(ans==result) cout<<" congratualions youwin" break; else { cout<<" Wrong answer: tryagain"; count++; } }   system("pause"); return0; } #include<iostream> using namespacestd; intmain() {intnum1,num2,max,count=0; doubleans; srand(time(0)); cout<<"Thisis a math practice program "; cout<<"Whatis the largest number you want your practice problems to have?"; cin>>max; cout<<"Enteryour answers after each problem "; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" + "<<num2<<" ="; cin>>ans; if(ans==(num1+num2)) cout<<"congratualions you win" break; else { cout<<"Wronganswer: try again"; count++; } } count=0; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" - "<<num2<<" ="; cin>>ans; if(ans==(num1-num2)) cout<<"congratualions you win" break; else { cout<<"Wronganswer: try again"; count++; } } count=0; num1=rand()%(max+1); num2=rand()%(max+1); while(count<3) { cout<<num1<<" * "<<num2<<" ="; cin>>ans; if(ans==(num1*num2)) cout<<" congratualions youwin" break; else { cout<<" Wrong answer: tryagain"; count++; } }
count=0; num1=rand()%(max+1); num2=((rand()%max)+1); while(count<3) { cout<<num1<<" / "<<num2<<" ="; cin>>ans; intresult=(int)(num1/num2); if(ans==result) cout<<" congratualions youwin" break; else { cout<<" Wrong answer: tryagain"; count++; } }   system("pause"); return0; }