May 6th, 2013, 12:46 AM
C++ assistance for my beginner class
using namespace std;
int num = 0;
int num2 = 0;
int user = 0;
int answer1 = 0;
int count = 0;
for(int i=1 ; i<=5 ; i++)
num = (rand()%8)+ 2;
num2= (rand()%8)+ 2;
cout<<"\nWhat is "<<num<<" x "<<num2<<endl;
cout<<"Wrong! -> "<<num<<" x "<<num2<<" = "<<answer1;
cout<<"\nYou got "<<count<<" out "<<"5 right!\n";
//I have this started for the below assignment. Can anyone please provide insight as to why I cant build on this solution.
Write a program that keeps generating two random numbers between 1 and 10 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.
Begin by asking the user how many questions to ask. Generate as many pairs of numbers as specified and get the answers from the user for each. If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer. Continue generating 2 new numbers until at least one is different from last time.
After presenting the number of pairs of numbers specified 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 again reads the number of questions to ask and generates that many pairs of numbers and reads the answers like before. If the answer is n or N, it quits generating numbers. If the answer is anything but y, Y, n or N, it tells the user to enter one of those letters until it is.
When the user decides to quit and has got less than 75% of all the questions right, the program displays the multiplication table (1x1 through 10x10) before terminating.
After displaying the table, randomly generate two numbers between 1 and 10, display their product and first number and ask the user to guess the second as more practice. For example, the program will generate 7 and 9 and will display 63 and 7 and the user must guess the second number (i.e.: 9). Do this 3 times. Do not repeat code. Use a loop to do this 3 times.
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:
Enter the number of questions to ask: 5
1. What is 3 x 9? 27
2. What is 2 x 7? 14
3. What is 8 x 9? 63
Wrong! 8 x 9 = 72
4. What is 6 x 3? 21
Wrong! 6 x 3 = 18
5. What is 2 x 9? 18
You got 3 out of 5 right which is 60%.
Play agian? [y/n] n
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!