I am trying to have the answer come out as a decimal

When i compile, the answer comes out as a number with no decimal. How would I make the answer come out with two decimal points? Like currency

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
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <iomanip>
using namespace std;

int calculateRetail(int, int);

int main()
{
	float wholecost;
		int markup;

	cout << "Please enter the wholesale cost and its markup percentage." << endl;
	cin >> wholecost;
	cin >> markup;

	while (wholecost < 0 || markup < 0)
	{
		cout << "Invalid numbers. Please try again." << endl;

		cout << "Please enter the wholesale cost and its markup percentage." << endl;
		cin >> wholecost;
		cin >> markup;
	}
	cout <<calculateRetail(wholecost, markup) << endl;

	//cost+(cost*percentage)

	cin.get();
	return 0;
}
int calculateRetail(int wholecost, int endcost)
{
	int cost;
	float wholesale=0;
	int markup=0;

	cost = wholecost + (wholesale*markup);
	cout << "The cost is " << setprecision(2) <<fixed<<showpoint<< cost<<endl;
	cin.get();
	return cost;
}
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
#include <iostream>
#include <iomanip>

double retail_price( double wholesale_cost, int percent_markup );

int main()
{
    double wholesale_cost;
    int pct_markup;

    std::cout << "Please enter the wholesale cost and its percent_markup percentage.\n" ;
    std::cin >> wholesale_cost >> pct_markup ;

    while( wholesale_cost <= 0 || pct_markup < 0 )
    {
        std::cout << "Invalid numbers. Please try again.\n" ;

        std::cout << "Please enter the wholesale cost and its percent_markup percentage.\n" ;
        std::cin >> wholesale_cost >> pct_markup ;
    }

    std::cout << "retail price: " << std::fixed << std::setprecision(2)
              << retail_price( wholesale_cost, pct_markup ) << '\n' ;
}

double retail_price( double wholesale_cost, int percent_markup )
{
    return wholesale_cost * ( 100.0 + percent_markup ) / 100.0 ;
}
Topic archived. No new replies allowed.