|
Write a shell program that tests a user’s ability to compute remainders of integer
division. Your program should prompt the user to enter two non-negative integers
(say x and n). The user will be asked to “guess” the result of x mod n. Your
program must restrict x and n to be less than 50.
If the user gives the correct answer, print a congratulations message. If the user is
wrong, provide the correct answer. The program should stop after trying 5 problems.
At the end it should show the number of correct answers and the number of wrong
answers. Error situations may arise and must be handled. If the x or n value is not
less than 50, or if n = 0, or if less than two integers are entered, print a warning
message and ask again for two numbers.
If the user terminates the program by typing ^C, your program should still print out
the number of correct and incorrect answers.
Here is a sample run of the program. Your prompts and output don’t have to look
exactly like this, but whatever you use should satisfy the above requirements. The
program output is in black, the user input is in red. “$” represents your prompt.
$ A4P3
Enter two integers less than 50: 99 6
An invalid value 99 was read, continuing to next round.
Enter two integers less than 50: 4 8
What do you think 4 mod 8 is? 4
*Y*E*S* - Congratulations, 4 mod 8 = 4
Enter two numbers less than 50:
No values entered, continuing to next round.
Enter two integers less than 50: 4 2
What do you think 4 mod 2 is? 0
*Y*E*S* - Congratulations, 4 mod 8 = 4
Enter two integers less than 50: 4 3
What do you think 4 mod 3 is? 0
Sorry, 4 mod 3 is 1.
You scored 2 correct and 1 incorrect.
$ |
|