Write a program that predicts behavior, based on chocolate consumption. Download the attached spreadsheet, and modify it.
The program starts like this:
The user enters data, and clicks Run. Validate the input, using the following rules.
- Name must be given.
- Gender must be F or M. Case doesn't matter. Leading and trailing spaces don't matter.
- Dark must be a number. It cannot be negative.
- Milk must be a number. It cannot be negative.
If there is an input error, show a message, and stop the program. For example:
Output the name, caffeine eaten, and behavior prediction. Output the name without leading or trailing spaces. You do not need to round the caffeine eaten.
There are 20 mg of caffeine in 100 grams of milk chocolate, and 43 mg of caffeine in 100 grams of dark chocolate.
The behavior prediction depends on gender.
For women:
Caffeine (mg) | Behavior |
---|---|
< 200 | No change |
>= 200 and < 400 | Hyper |
>= 400 | Sarcasm overload |
For men:
Caffeine (mg) | Behavior |
---|---|
< 150 | No change |
>= 150 and < 300 | Jerk |
>= 300 | The defendant pleads… |
For example:
Upload your workbook.
(If you were logged in as a student, you could submit an exercise solution, and get some feedback.)