I am writing a program that computes the tax and tip on a restaurant bill for a patron with a \$44.50 meal charge. The tax is 6.75 of the meal cost. The tip is 15 percent of the total after adding the tax. I have to dislay the meal cost, tax amount, tip amount, and total bill on the screen, is my logic right?

``````#include <iostream>
using namespace std;

int main()
{
//Declare variables

double
subTotal,// charge paid for meal

waitressTotal, //the toal the waitress gets for the meal
totalTax,   //total paid
salesTip,  //sales tip paid to waitress
grandTotal, //grand total for meal
mealCost;  //cost for the entire meal
float      tax;     //Base sales tax

//Calculate restauraunt bill
subTotal = 44.50;
tax = 6.75;
totalTax;

totalTax = subTotal + tax;
waitressTotal = subTotal + totalTax * 0.15;
grandTotal = subTotal + waitressTotal;

cout<<"The amount for the meal is: \$"<<subTotal<<endl;
cout<<endl;
cout<<"The tax amount for the meal is: \$"<<totalTax<<endl;
cout<<endl;
cout<<"The tip amount for the meal is: \$"<<waitressTotal<<endl;
cout<<endl;
cout<<"The total bill is: \$"<<grandTotal<<endl;
cout<<endl;

system("pause");

return 0;
}``````

Any help is greatly appreciated..

You can surely run the program yourself and see whether the output is right.

Thats the problem...it looks all wrong to me...the numbers look way off..ive tried everything and i dont know how to fix it

test it the code is fine.
couldn't see any logic wrong from your code.

Basics of percentages:

If you wish to calculate a percentage (P) from a total (T) you
need `T*(P/100.0)` Your tax is 6.75 % so, you write totalTax = subTotal+tax.
Now the mathematicians say there are three numbers 0,1, infinity.
BUT the key thing to remember with any equation is to test those numbers. You should do that here : If you have a meal costing nothing [go easy of the water ;)], you would pay zero tax.
But you have an addition not a multiplications.

Total tax is the total tax, it should not include the meal value.

You also violate the precidence rules, the tip, is 15% of the (subTotal+totalTax).

Please keep it simple first time, do one part at a time, and use simple percentages so it is easy to debug.

Does this look kind of better?

``````#include <iostream>
using namespace std;

int main()
{
//Declare variables

double
subTotal,// charge paid for meal
waitressTotal, //the toal the waitress gets for the meal
totalTax,   //total paid
salesTip,  //sales tip paid to waitress
grandTotal, //grand total for meal
mealCost;  //cost for the entire meal
float      tax;     //Base sales tax

//Calculate restauraunt bill
subTotal = 44.50;
tax = 6.75;

totalTax = subTotal + tax;
waitressTotal = (subTotal + totalTax) *(0.15);
grandTotal = (subTotal) + waitressTotal;

cout<<"The amount for the meal is: \$"<<subTotal<<endl;
cout<<endl;
cout<<"The tax amount for the meal is: \$"<<totalTax<<endl;
cout<<endl;
cout<<"The tip amount for the meal is: \$"<<waitressTotal<<endl;
cout<<endl;
cout<<"The total bill is: \$"<<grandTotal<<endl;
cout<<endl;

system("pause");

return 0;
}``````

why the
totalTax = subTotal + Tax??

Additionally, please test it, then then see what happens as you change bits!!!

For example what do you think `grandTotal = (subTotal) + waitressTotal;` and `grandTotal = subTotal + waitressTotal;` would change?

I just started out in C++, so im having trouble understanding how things really work in this language...i got a totally different answer in working it out on the calculator...I got like 58.someting...i took the 44.50 and multiplied the tax and got the 300.0oo. whatever...i took that and added the tax times the 15 percent which gave me the waitress total. then for the grand total, I took the subtotal, (47.50 and added the waitress total)

You also violate the precidence rules, the tip, is 15% of the (subTotal+totalTax).

I don't think there's a hard and fast rule, but I think generally you base the tip on the pre-tax amount, though internet research finds pages recommending both ways, with a majority recommending basing the tip on the pre-tax amount. The OP might want to ask her teacher to make sure (assuming it's an assignment?) they have the same idea of how to calculate the tip (he/she who does the grading is always right).

I just started out in C++, so im having trouble understanding how things really work in this language...i got a totally different answer in working it out on the calculator...I got like 58.someting...i took the 44.50 and multiplied the tax and got the 300.0oo. whatever...i took that and added the tax times the 15 percent which gave me the waitress total. then for the grand total, I took the subtotal, (47.50 and added the waitress total)

Regardless of your C++ experience, you need to have exact input and output to check, before you even start programming. Make sure it's right, THEN check your C++ output against what you have already decided is right. That includes deciding what the formulas are supposed to be. Make a spreadsheet, plug some numbers into a calculator, write them down, but they need to be exact if you hope to be successful in your program since you are going to have to plug in some formulas.

I would change the variable names, particularly "totalTax". You already have "tax". What's the difference? Maybe "totalTax" should be "totalWithTax" or whatever. Myself, I would have four variables:

``````double mealTotal // same as subtotal
double tax;
double tip;
double total;   // = mealTotal + tax + tip``````

I am writing a program that computes the tax and tip on a restaurant bill for a patron with a \$44.50 meal charge. The tax is 6.75 of the meal cost. The tip is 15 percent of the total after adding the tax.

Missed this in the first post before. If that's the rule, that's the rule. Base the tip on the post-tax amount.

First :
Make all your vars of type float.
The time I have to pay a meal that exceeds the range of a float I stop eating let alone that I have to pay in a range that would exceed a double type!
Second :
Why are you paying your meal twice?
Was the waitress that good?
subTotal = 44.50;
tax = 6.75;

totalTax = subTotal + tax;
waitressTotal = (subTotal + totalTax) *(0.15);
grandTotal = (subTotal) + waitressTotal;

TotalTax = 44.50+6.75=51.25
waitressTotal =(44.50+51.25)*0.15=14,3625

could you help me with this pls?about c++..

this is the given..compute for the tax based on the ff.

GROSS PAY
above 15000
above 20000
1000 and below

TAX RATE
9%
5%
3%

any help will be gladly appreciated.. X\