### Need help with my beginners restaurant program.(mainly the tax)

Hello everyone I am working on my first C++ program ahead of schedule and I think I almost have it down. The only thing that has me scratching my head is that the tax keeps coming out to 8 dollars instead of 8.25. Thank you all for your time and input =)

This is the goal I am looking to get as my output:

Test case‐1:
Program input:
> Enter meal cost (in \$): 100.00
>Enter tax (in percentage): 8.25
> Enter tip (in percentage): 15
Program output:
Bill summary:
===========
Meal cost:  \$100.00
Tax amount: \$8.25
Tip amount: \$15.00
Total bill: \$123.25

This is my code so far and everything is working accept the tax amount which of course messes up my total bill by .25 cents.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include using namespace std; int main() { double meal_cost = 100.00, tax = 0.0825, tip = .15; int Tax_MC, bill, total_bill, Tip_TB; cout << "What is the meal cost?:"; cin >> meal_cost; cout << "What is the tax amount in percent?:"; cin >> tax; cout << "What is the tip amount in percent?:"; cin >> tip; //Formula for the tax of the meal cost. Tax_MC = mealCost * tax; //Formula for the amount of the bill. bill = mealCost * tip; //Forumula for the cost of the tip from the bill. Tip_TB = mealCost + taxTotal + tipTotal; //Formula for total amount of the bill plus tip. //Display the results cout << "Bill summary" << endl; cout << "============" << endl; cout << "The meal cost came up to \$" << meal_cost << endl; cout << "The tax amount of the meal cost is \$" << Tax_MC << endl; cout << "The tip came up to \$" << Tip_TB << endl; cout << "The total amount of the bill is \$" << total_bill << endl; system("pause"); return 0; }``````
Last edited on
Integer truncation.

Make the variables in questions doubles, not integers.
Im sorry iHutch im not exactly sure what that means. Do I take out the int from
int Tax_MC,
bill,
total_bill,
Tip_TB;

and just leave it as doubles all the way down? I'm sorry if this is a silly question I am really just starting C++.

**EDIT** I believe to have got it working now thanks a bunch Hutch

This is my finished code

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````#include using namespace std; int main() { double meal_cost = 100.00, tax = 0.0825*meal_cost, tip = .15, Tax_MC, total_bill, Tip_TB; //Input for the meal cost. cout << "What is the meal cost?:"; cin >> meal_cost; //Input for tax amount in percent. cout << "What is the tax amount in percent?:"; cin >> tax; //Input for tip amount in percent. cout << "What is the tip amount in percent?:"; cin >> tip; //Formula for the tax of the meal cost. Tax_MC = meal_cost * tax; //Forumula for the cost of the tip from the bill. Tip_TB = meal_cost * tip; //Formula for total amount of the bill plus tip. total_bill = meal_cost + Tax_MC + Tip_TB; //Display the results cout << "Bill summary" << endl; cout << "============" << endl; cout << "The meal cost came up to \$" << meal_cost << endl; cout << "The tax amount of the meal cost is \$" << Tax_MC << endl; cout << "The tip came up to \$" << Tip_TB << endl; cout << "The total amount of the bill is \$" << total_bill << endl; system("pause"); return 0; }``````
Last edited on
Yeah, everything as doubles works better here.

Remember, integers can only be whole numbers. They also don't round up or down where calculations are concerns. They just truncate.

This is why your \$8.25 became \$8.
Last edited on