In: Computer Science
Modify the following C++ program to count the number of correct and incorrect responses typed by the student. After the student types 5 answers, your program should calculate the percentage of correct responses. If the percentage is lower than 75 percent, your program should print “Please ask for extra help” and then terminate. If the percentage is 75 percent or higher, your program should print “Good work!” and then terminate. The program is as follows:
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
const int no_runs = 5;
int run, n1,n2,answer;
srand((unsigned int)time(NULL));
for(run = 0;run<no_runs;run++)
{
n1 = rand()%9 + 1;
n2 = rand()%9 +1;
while(true)
{
cout<<"What is the product of "<<n1<<" and
"<<n2<<": ";
cin>>answer;
if(answer==n1*n2)
break;
cout<<"No. Please try again."<<endl;
}
cout<<"Very good!"<<endl;
}
system("pause");
return 0;
}
#include<iostream> #include<iomanip> #include<cstdlib> #include<time.h> using namespace std; int main() { const int no_runs = 5; int run, n1,n2,answer, correct; double percent; srand((unsigned int)time(NULL)); // Looping through no_runs times for(run = 0;run<no_runs;run++) { // Generating random number between 1 to 9 n1 = rand()%9 + 1; // Generating random number between 1 to 9 n2 = rand()%9 +1; // Printing a message asking for product of n1 and n2 cout<<"What is the product of "<<n1<<" and "<<n2<<": "; // Getting answer from user cin>>answer; // Comparing the user answer with actual answer if(answer==n1*n2) // Incrementing the correct variable to track the current correct answer count correct++; } // Calculating percentage of correct answers percent = (1.0*correct)/no_runs; // Checking if the correct answer percentage is less than 75 if(percent < 75) // Printing a message cout<<"Please ask for extra help"<<endl; // if the correct answer percentage is greater than or equals to 75 else // Printing a message cout<<"Very good!"<<endl; system("pause"); return 0; }