← Back
Code Challenge 1.5 - Tip Calculator
Objective
Create a console application that helps users calculate the tip amount based on their bill subtotal and a given tip percentage.
Terms
Bill/Subtotal - How much your food and drink cost
Tip/Gratuity - How much money you would like to give your server. For example, people typically tip 15% to 20% of the subtotal.
Total - The sum of the bill and tip amount.
Examples
- A $10 bill with 20% tip = Tip $2; Total $12
- A $25 bill with 18% tip = Tip $4.50; Total $29.50
Skills to Practice
- Prompting a user for input
- Saving user input to variables
- Converting input to the correct data type (if necessary)
- Performing arithmetic calculations
- Formatting custom output using variables
Challenge Tasks
- Create a console project named Challenge 1-4.
- Prompt the user to enter the bill subtotal.
- Prompt the user to enter the tip percentage as a whole number. For example, 20 means 20%.
- Calculate the tip amount using the formula Tip = Subtotal × (tip percentage / 100).
- Calculate the total amount.
- Display the calculated tip amount and total amount to the user in a clear and formatted manner.
- If you want to ensure your dollar amounts always have two decimal places, search “add leading zeros to double in C#”.
Sample Output
--- Tip Calculator ---
Enter the bill subtotal: 50.00 [Enter]
Enter the tip percentage: 15 [Enter]
Tip amount: $7.50
Total amount: $57.50