Function help

im basically trying to make a driver program. So i made a function but having trouble calling the function. Help with the cout statement outputting the amount in dollar form such as $2.00 or $3.45. The set precision and show point isnt working for me. thanks

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
#include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;


double calculateRetail(double, double);

int main(int argc, char *argv[])
{
    

double wholesale;
int markup;

cout << "Enter Items whole cost.\n";
cin >> wholesale;
cout << "Enter items Markup percentage.\n";
cin >> markup;

cout << "Your items retail price is $" << calculateRetail(wholesale, markup) << "." << endl;
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

double retail, wholesale;
double calculateRetail(double wholesale, double markup)
{


retail = wholesale + (wholesale*markup/100);
return retail;
}
Last edited on
closed account (zb0S216C)
When you invoke a function, you're supposed to pass a value equivalent of the type specified. For instance, you've specified that calculateRetail() takes 2 floating-point numbers. So when you call that function, you pass it two floating-point values, like so:

calculateRetail(1.0, 2.0)

Wazzak
What if i dont know the value until the user input the numbers?
closed account (zb0S216C)
Then don't invoke the function until you do... or provide default values.

Wazzak
The project says to write a function that receives the wholesale cost and percentage as arguements and returns the retail price of the item. so i wont know what the values are until the user inputs the info. so when i enter 5 or 5.00 and 50 for teh percentage it only displays 7.5 instead of 7.50
The set precision and show point isnt working for me. thanks
But in your code you don't use them...
http://cplusplus.com/reference/iostream/manipulators/setprecision/
http://cplusplus.com/reference/iostream/manipulators/fixed/
I tried but they did not work so i removed them as they were not usefull.
So i solved my own problem :)

i needed to include
 
cout << ........ << setprecision (2) << fixed << ..........endl;


thanks anyways
Topic archived. No new replies allowed.