Question

Write a C program that requests a US dollar amount from the user that will represent...

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

Homework Answers

Answer #1
#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;
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in c++ Write a program that asks the user for the speed of a vehicle (in...
in c++ Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. It should use a loop to display the total distance traveled. The speed traveled should be limited by the fastest speed achieved by a car thus far. Values should not be negative.•Ex: if hours = 3 and speed = 40, then the program should display•Hour 1: Distance Traveled: 40 miles•Hour 2: Distance Traveled: 80...
In one C++ program: a.) Write a code to asks the user for her/his full name...
In one C++ program: a.) Write a code to asks the user for her/his full name b.) Write a code that asks the user to enter information related to a car the user likes (year, make, model) c.) Write a code that asks the user to enter the amount of time or gas or money the user spends to commute weekly d.) Write a code that asks the user to enter the number Kwh (used monthly) and compute the user...
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in...
JAVA ASSIGNMENT 1. Write program that opens the file and process its contents. Each lines in the file contains seven numbers,which are the sales number for one week. The numbers are separated by comma.The following line is an example from the file 2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36. The program should display the following: . The total sales for each week . The average daily sales for each week . The total sales for all of the weeks .The average weekly sales .The week number...
How much money do you think you would earn in a period of 30 days if...
How much money do you think you would earn in a period of 30 days if you were paid as follows: one cent for the first day, two cents for the second day, four cents for the third day, eight cents for the fourth day, and so on (i.e. your salary doubles each day)? Do you think you would make very little money, just a few dollars, at the end of the 30-day period? Let us write a program to...
C++. Write a program that draws a rocket shape on the screen based on user input...
C++. Write a program that draws a rocket shape on the screen based on user input of three values, height, width and stages. The type of box generated (i.e.. a hollow or filled-in) is based on a check for odd or even values input by the user for the box height (or number of rows). Here is the general specification given user input for the height of the box..... Draw a hollow box for each stage if the value for...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT