Hello,
This may seem like a simple easy fix, however I am not able to figure it out currently. I am new to coding and this is one of the first I have tried to write by myself. Can you please take a look at it and let me know what I did wrong. So far I know I need to figure out how to correctly add for the total and to get the tip amount from that total. Also I can't figure out how to display the decimals not whole numbers. Here are the instructions for this code.
Write a program that informs a user of their meal charge. Create a variable and assign it a value for the meal charge (e.g. $32.95). The program should then compute the tax and tip on the restaurant bill. The tax should be 6.75 percent of the meal cost. The tip should be 20 percent of the total after adding the tax.
Display the meal cost, tax amount, tip amount, and total bill on the screen.
Any help or information on what I should change or add I would appreciate it. Thanks.
/***************************************************
*Purpose: Shows the bill and computes tax and tip
***************************************************/
#include <iostream>
#include <string>
using namespace std;
int tax(int);
int tip(int);
int total(int);
int main ()
{
int cost;
cout << "Please enter meal cost " ;
cin >> cost;
cout << "The meal cost is $ " << cost << endl;
cout << "The tax amount is $ " << tax(cost) << endl;
cout << "The total bill is $ " << total(cost) << endl;
cout << "The recommended tip amount is $ " << tip(cost) << endl;
return 0;
}
#include <iostream>
#include <iomanip> //for std::setprecision
int main()
{
// 1. Create a variable and assign it a value for the meal charge (e.g. $32.95).
constdouble meal_charge = 52.65 ;
// 2a. The tax should be 6.75 percent of the meal cost.
constdouble tax_rate = 6.75 / 100.0 ;
// 2b. compute the tax on the restaurant bill.
constdouble tax_amount = meal_charge * tax_rate ;
// 2c. compute the total after tax
constdouble total_after_tax = meal_charge + tax_amount ;
// 3a. The tip should be 20 percent of the total after adding the tax.
constdouble tip_rate = 20.0 / 100.0 ;
// 3b. compute the tip amount (of the total after adding the tax)
constdouble tip_amount = total_after_tax * tip_rate ;
// 3c. calculate the total bill amount
constdouble total_bill_amount = total_after_tax + tip_amount ;
// 4. Display the meal cost, tax amount, tip amount, and total bill on the screen.
std::cout << std::fixed // display values in fixed-point notation
<< std::setprecision(2) // with two significant digits after the decimal point
<< " meal cost: $" << meal_charge << '\n'
<< "tax amount: $" << tax_amount << '\n'
<< "tip amount: $" << tip_amount << '\n'
<< "total bill: $" << total_bill_amount << '\n' ;
}