CAN YOU PLEASE ANSWER COMPLETE IN C++ (Computers in Education) Computers are pla
ID: 3725819 • Letter: C
Question
CAN YOU PLEASE ANSWER COMPLETE IN C++
(Computers in Education) Computers are playing an increasing role in education. Write a program that helps an elementary school student learn addition. Use rand to produce two positive one-digit integers. It should then type a question such as “How much is 6 plus 7?”. The student then types the answer. Your program checks the student’s answer. If it is correct, print “Very good!”, then ask another addition question. If the answer is wrong, print “No. Please try again.”, then let the student try the same question repeatedly until the student finally gets it right.
Explanation / Answer
#include<iostream>
#include <cstdlib>
using namespace std;
int main()
{
while(1)
{
int a=rand()%10; //Generatin first random number
int b=rand()%10; //Generating secnd randon number
int sum_original=a+b; //Storing hte correct sum od an and b
cout<<"Two numbers are "<<a<<" "<<b<<" ";
int flag=0;
while(1)
{
cout<<"How much is "<<a<<" "<<"plus "<<b<<" ";
cout<<"Enter sum of "<<a<<" and "<<b<<" is"<<" ";
int sum;
cin>>sum; //Storing the input by the user
if(sum==sum_original) //Cheking th e equality condition if true then
{
cout<<"Very Good!!"<<" ";
flag=1;
break;
}
else{ //If sum entered is incorrect
cout<<"No.Try again please!!!"<<" ";
flag=0;
continue;
}
}
if(flag==1) //Asking user whether to continue pratice or end the program
{
cout<<"Do you want to try another sum problem.Press y for yes or press n for no"<<" ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
continue;
}
else{
break;
}
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.