I am in need with some help please

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;
}

int tax( int n)
{
return n * .675;
}

int total( int n)
{
return n + n;
}

int tip( int n)
{
return n * .2;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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).
    const double meal_charge = 52.65 ;

    // 2a. The tax should be 6.75 percent of the meal cost.
    const double tax_rate = 6.75 / 100.0 ;
    // 2b. compute the tax on the restaurant bill.
    const double tax_amount = meal_charge * tax_rate ;
    // 2c. compute the total after tax
    const double total_after_tax = meal_charge + tax_amount ;

    // 3a. The tip should be 20 percent of the total after adding the tax.
    const double tip_rate = 20.0 / 100.0 ;
    // 3b. compute the tip amount (of the total after adding the tax)
    const double tip_amount = total_after_tax * tip_rate ;
    // 3c. calculate the total bill amount
    const double 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' ;
}
A double or float will display the number in decimal, whilst an integer will only display a whole number.
Thank you for explaining each step JLBorges, and thank you for explaining my whole number issue An Integer.
Topic archived. No new replies allowed.