Write a C program that requests a US dollar amount from the user that will represent a restaurant bill. The program will then calculate 3 tip amounts for this bill: 10%, 15%, and 20%. Use defined constants for the tip percentages. You may use your percentages (for example) as either 10 or 0.10. If you use 10, you will need to divide this by 100 in your calculations. A sample run of this program might look like this (user input is in red): Please enter a restaurant bill amount:
42 A 10% tip on $42 is $4.20
A 15% tip on $42 is $6.30
A 20% tip on $42 is $8.40
HINT: in order to display a % in output, use %% in the format string
#include <stdio.h> int main() { int amount; double TIP_AMOUNT_10 = 0.10; double TIP_AMOUNT_15 = 0.15; double TIP_AMOUNT_20 = 0.20; printf("Please enter a restaurant bill amount: "); scanf("%d", &amount); printf("A 10%% tip on $%d is $%.2lf\n", amount, amount*TIP_AMOUNT_10); printf("A 15%% tip on $%d is $%.2lf\n", amount, amount*TIP_AMOUNT_15); printf("A 20%% tip on $%d is $%.2lf\n", amount, amount*TIP_AMOUNT_20); return 0; }
Get Answers For Free
Most questions answered within 1 hours.