Classwork 6: Variables and I/O
To practice using variables and console I/O functions printf() and scanf().
You and your friends go out to eat at a restaurant. The waiter brings you the bill. Now you have to figure out how much each of you has to pay. You decide to just split the bill equally, since nobody remembers how much them menu items cost.
Write a program to help you compute what each person has to pay (including the tip). Your program should prompt the user to input the total restaurant bill. Then it should ask how many people are in the party. Finally, it prints out what each person has to pay, if you wanted to give the waiter a 20%, 18%, 15% or 10% tip.
A sample run of your program should look like this:
What is the total amount of the bill? 112.75 How many people are in your party? 5 With 20 percent tip, you should each pay $27.060000 With 18 percent tip, you should each pay $26.609000 With 15 percent tip, you should each pay $25.932500 With 10 percent tip, you should each pay $24.805000
For your computations, you can use * for multiplication and / for division.
Optional: print out the dollar amount nicely, so it doesn't show a fraction of a penny.
Use the script command to record several sample runs of your program. Each sample run should test your program with different input data. (What happens if you enter 0 for the number of people?) Remember to exit when you are done with script. Then submit your program and sample run with
submit cs104_chang cw06 tip.c submit cs104_chang cw06 typescript
Be sure to logout completely when you have finished!