Reference no: EM132356398
Exercise: Math quiz
Topics : While loops for program control, while loops for input validation, running total, selection statements
1. Write a program that randomly generates two integers between 1 and 10. It should then prompt the user to select +, -, /, or *. The program should then prompt the user for the answer to the math problem involving the two random integers and the selected operation. The program then tells the user whether or not they are correct.
2. Add an input validation loop that ensures the user can only enter +, -, /, or *
3. Add a program control loop that allows the user to continue answering questions until they quit.
4. Add a running total that prints out how many they get correct and how many the get incorrect after they quit the program.
Sample runs:
Hi and welcome to the math quiz!
Do you want to answer a question (Y/N)? Y
Do you want to +, -, /, or * (select one): *
The problem is: 5 * 8
Enter the answer: 40
You are correct!
Do you want to answer another question (Y/N)? Y
Do you want to +, -, /, or * (select one): @
That is not a valid selection. Do you want to +, -, /, or * (select one): /
The problem is: 2 / 10
Enter the answer: .2
You are correct!
Do you want to answer another question (Y/N)? Y
Do you want to +, -, /, or * (select one)? &
That is not a valid selection. Do you want to +, -, /, or * (select one): =
That is not a valid selection. Do you want to +, -, /, or * (select one): +
The problem is: 9 + 1
Enter the answer: 11
Incorrect.
Do you want to answer another question (Y/N)? N