I need to write a c++ program to do this. Fun with Multiplication should begin b
ID: 3850790 • Letter: I
Question
I need to write a c++ program to do this.
Fun with Multiplication should begin by prompting the user for how many multiplication problems to solve. How Many Multiplication Problems: For each problem the application should generate two random numbers between 1 and 12 and present them in multiplication form: ie. 6 X 4 = ?. The application should continue to present each problem until the correct answer is entered. The application should acknowledge a correct response with an affirmative statement. 6 X 4 = 6 X 4 = 6 X 4 = Correct! 12 X 9 = ? After serving the specified number of multiplication problems the application should congratulate the user on completing the task and display a statistical summary of their session. Congratulations on Completing your Mission! Problems: 5 Guesses: 8 Accuracy: 62.5% Finally, your application should query the user to ‘Go Again?’, If the response is ‘Y’ or ‘y’ the application should loop to the ‘How many problems’ prompt. If the response if ‘N’ or ‘n’ the application should offer a final thanks and end. Thanks for using Fun with Multiplication!
Explanation / Answer
c++ code for mutiplication game:
#include <cmath>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
char yes,no;
int a, b, answer, guess;
cout << "Welcome to the Multiplication Game" << endl;
yes='Y';
no='N';
while ((yes=='y') || (yes=='Y'))
{
srand ( time(NULL) );
a = rand() % 10;
b = rand() % 10;
cout << "What's " << a << "x" << b << "?";
cin >> guess;
answer = a * b;
while (answer != guess)
{
cout << "No. Please try again" << endl;
cout << "What's " << a << "x" << b << "?";
cin >> guess;
}
if (answer == guess)
cout << "Correct. Try another (y/n)?";
cin >> yes;
}
while((no=='N') || (no=='n'))
{
cout<< "Bye! Thanks for playing"<<endl;
exit(0);
}
return 0;
}
output screenshot:
Welcome to the Multiplication Game
What's 5x3?15
Correct. Try another (y/n)?
y
What's 4x3?12
Correct. Try another (y/n)?y
What's 0x4?4
No. Please try again
What's 0x4?0
Correct. Try another (y/n)?n
Bye! Thanks for playing