LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 758|回复: 1

hoho, Who can do this question?

 关闭 [复制链接]
发表于 2006-9-29 01:02:20 | 显示全部楼层 |阅读模式
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.
$
发表于 2006-9-29 01:13:48 | 显示全部楼层
hoho, you are fired.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表