Write a program that keeps generating two random numbers between 2 and 9 and asks the user for the product of the two numbers, e.g.: "What is 4 x 6?". If the user answers correctly, the program responds with "Right!"; otherwise, it displays: Wrong! 4 x 6 = 24.
Generate 5 such pairs of numbers and get the answers from the user. If at any time, both numbers are the same as last time, generate two new numbers. Continue generating 2 new numbers until at least one is different from last time.
After presenting 5 pairs of numbers and getting the answers, display how many the user got right; e.g.: You got 4 of 5 right. Then, ask if he or she wants to play again, like so: "Do you want to play again? [y/n]". If the user answers with 'y' or 'Y', it generates another 5 pairs of numbers and asks for their products. If not, it quits generating numbers.
If the user gets less than 25% of the last round of 5 questions, the program displays the multiplication table before terminating. Use a nested for loop to display the table. A bunch of cout statements will not be acceptable. You must also use a loop for any part that calls for repetition such as generating 5 pairs of numbers.
The following is a sample interaction between the user and the program:
What is 3 x 9? 27
Right!
What is 2 x 7? 14
Right!
What is 8 x 9? 63
Wrong! 8 x 9 = 72
What is 6 x 3? 21
Wrong! 6 x 3 = 18
What is 2 x 9? 18
Right!
You got 3 out of 5 right which is 60%.
Play agian? [y/n] n
(If the user had answered with y or Y the program would generate another 5 pairs of numbers and would again display the score and ask to do it again or not. But, because the user answered with n (or N), it quits, but before quitting, it prints the multiplication table since the score was less than 75%).
We're not going to do the whole assignment for you. What specifically is giving you trouble?
Larger projects seem more complicated than they are. Break it up into smaller parts.
For example... the first thing the assignment tells you to do is "generate two random numbers between 2 and 9". Can you do that?
Once you do that, move on to the next step: "ask the user for the product of the two numbers, e.g.: "What is 4 x 6?""
etc
Just take it one step at a time.
EDIT: also, give us more than 10 minutes to respond. We aren't just sitting on the boards 24/7 waiting to answer posts. Sometimes it takes us a while to see them and respond.
I need help now on how to filter out the random #s from being the same just as the direction say.
Also,need help on the part where I ask the user to enter "yes or no" to re-enter
into the loop.
heymrjack10, I know this isn't part of your question at all but if you're just learning c++ now or something, I would highly recommend getting into the habit of always initializing your variables to 0 or NULL;
so instead of
1 2
int num,num2,user;
int answer1,count;
you should write it like this
1 2 3 4 5
int num = 0;
int num2 = 0;
int user = 0;
int answer1 = 0;
int count = 0;
this can save you massive headaches when debugging, and I don't just mean for ints, I mean for just about everything, ever. Don't just declare it, initialize it!
#include <ctime>
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int num = 0;
int num2 = 0;
int num3 = 0;
int num4 =0;
int user = 0;
int answer1 = 0;
float count = 0;
float percent;
char ch;
srand(unsigned(time(0)));
for(int i=1 ; i<=5 ; i++)
{
{
num = (rand()%8)+ 2;
num2= (rand()%8)+ 2;
answer1=num*num2;
cout<<"\nWhat is "<<num<<" x "<<num2<<endl;
cin>>user;