My code #include using namespace std; int main () { float meal_cost,total_bill,tax_amount,tip_amount; cout <<"Enter a meal charge:"; cin >> meal_cost; tax_amount = 0.0675 * meal_cost; tip_amount = 0.2 * (tax_amount + meal_cost); total_bill = meal_cost + tax_amount + tip_amount; cout <<"The meal cost is"<< meal_cost <> meal_cost;", and "tax_amount = 0.0675 * meal_cost;". These two lines should be equal tabbed with the rest within the main() brackets, though those might be a copy-paste error rather than an error in your code. However, this code should output the correct answer, and everything I've pointed out has been purely aesthetic issues. 2- Your code looks just fine I would just do some things different. It is easier if you make space between lines in your code especially between the variables and the rest. Your variables had clear names however it may be better to shorten them a bit like instead of total_bill you can put total or bill. You could also put tax_amt instead of tax_amount. I also believe it would be easier if you would add more comments to you code so you and others can understand it better.
My code
#include <iostream>
using namespace std;
int main ()
{
float meal_cost,total_bill,tax_amount,tip_amount;
cout <<"Enter a meal charge:";
cin >> meal_cost;
tax_amount = 0.0675 * meal_cost;
tip_amount = 0.2 * (tax_amount + meal_cost);
total_bill = meal_cost + tax_amount + tip_amount;
cout <<"The meal cost is"<< meal_cost <<endl;
cout <<"tax amount" << tax_amount <<endl;
cout <<"tip amount" << tip_amount <<endl;
cout <<"total bill" << total_bill <<endl;
return 0;
}
Two Comment I got:
1- Although this one is one of the shortest ones I've seen, I think the readability of the code could be improved with a couple of blank lines here and there. I'm pretty sure the computer just skips them with no effect on run speed. Also, there are a couple of weirdly placed tabs for the lines "cin >> meal_cost;", and "tax_amount = 0.0675 * meal_cost;". These two lines should be equal tabbed with the rest within the main() brackets, though those might be a copy-paste error rather than an error in your code. However, this code should output the correct answer, and everything I've pointed out has been purely aesthetic issues.
2- Your code looks just fine I would just do some things different. It is easier if you make space between lines in your code especially between the variables and the rest. Your variables had clear names however it may be better to shorten them a bit like instead of total_bill you can put total or bill. You could also put tax_amt instead of tax_amount. I also believe it would be easier if you would add more comments to you code so you and others can understand it better.
For Question I attached the pricture
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images