Write a program to work out the price for catering a party on the planet Phelte. There are four partying species: squils, dephants, smoooshshs, and pleezles. Different numbers of each can be invited to a party. There's a limit to the number that can be invited. For example, smoooshshs are big, so you can only invite a few. Pleezles are tiny, so you can invite many.
The price depends on the amount of food and water needed.
Each species eats the same food: toes. This table shows the maximum number of each species you can invite, and the kilos of toes an individual will eat.
Species | Max | Toes consumed (kilos) |
---|---|---|
Squils | 30 | 0.4 |
Dephants | 50 | 0.6 |
Smoooshshs | 10 | 1.2 |
Pleezles | 1,000 | 0.08 |
A kilo of toes is priced at GC 15.9. (That's galactic credits.)
One liter of water is needed for every kilo of toes. The price of a liter of water depends on the type of water ordered.
- Salt water is GC 0.2 per liter.
- Fresh water is GC 0.7 per liter.
- Distilled water is GC 1.3 per liter.
Your program should ask the user how many of each species will be at the party, and the type of water they want. Validate all input.
- Species numbers must be integers that are from zero to the species max given in the table above.
- Water is one of the three types: S, F, or D. Let users enter upper or lowercase values, and extra spaces if they want.
Output kilos of toes needed, toes price, water price, and the total, as shown below. Round all numbers to at most two decimal places.
Here's some IO:
- Party catering cost
- ===================
- How many squils? 1
- How many dephants? 1
- How many smoooshshs? 1
- How many pleezles? 1
- Water type (S for salt, F for fresh, D for distilled)? s
- -----------------------------
- Toes (kilos): 2.28
- Toes price (GC): 36.25
- Water price (GC): 0.46
- =============================
- Total (GC): 36.71
Here's some more, showing validation:
- Party catering cost
- ===================
- How many squils? some
- Sorry, you must enter a whole number.
- How many squils? 1.4
- Sorry, you must enter a whole number.
- How many squils? -33
- Sorry, please enter a whole number between 0 and 30.
- How many squils? 232
- Sorry, please enter a whole number between 0 and 30.
- How many squils? 10
- How many dephants? 10
- How many smoooshshs? 11
- Sorry, please enter a whole number between 0 and 10.
- How many smoooshshs? 10
- How many pleezles? 100
- Water type (S for salt, F for fresh, D for distilled)? not sure
- Sorry, you must enter S, F, or D.
- Water type (S for salt, F for fresh, D for distilled)? F
- -----------------------------
- Toes (kilos): 30.0
- Toes price (GC): 477.0
- Water price (GC): 21.0
- =============================
- Total (GC): 498.0
The number of zeros don't have to match exactly. 498, 498.0, and 498.00 are all OK.
Other requirements:
- Write just one function that will get the number of a species from the user. Call the function four times.
- Write a function that will get the type of water from the user.
- Write a function that will compute the cost of the water, given kilos of toes and water type.
- You can add other functions if you want.
- Format the output as shown in the IO samples. Include the prompts and the underlining.
- You can add other functions if you want.
Upload your solution here, not to Moodle. The usual programming standards apply.