//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
Right!
2. What is 2 x 7? 14
Right!
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
Right!
You got 3 out of 5 right which is 60%
Play agian? [y/n] n.
and provide that "If at any time, both numbers are the same as last time, generate two new numbers before asking for the answer."
As for the programming style you should declare names in that declarative regions where they are used, For example in your code variable answer1 (why is it named answer1 and not simply answer?) is used only within declarative region of the for statement. So it should be declared in this declarative region.
Some names should be introduced for magic numbers 10 and 11 ( is 11 connected with 10?).
Further in fact you are doing a stupidity selecting the same number from the array as its index. That is you are gettting for example an index equal to 5 and then you are accessing the array that to get number 6.:) It is too complicated. It is enough to get a random number in one step.
Moreover the code has a bug because random numbers that you are generating are in the range 0 - 10 but acceptable indexes are in the range 0 - 9.
Then it is better to substitute two if statements for one if-else statement.
Also it is better to have one variable right because variable wrong is calculated simply as 5 - right.
you're right,,I was wrong in 11,,its should be 10,,
thenkz for the lesson..
and,,
what you mean "selecting the same number from the array as its index"?
You are getting a random number and then accessing the array that to get the original random number + 1. I do not think that to add 1 to a number you should define an arrray. It would be simpler to write without using the array