difficulties with functions
I can't figure out the error. :/
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <iostream>
#include <iomanip>
using namespace std;
// function prototypes
double getSales(double);
double calcComm(double);
void dispComm(double);
void calcTotal(double);
double dispTotal(double);
int main()
{
double sales= 0.0;
double total= 0.0;
getSales(sales);
calcComm(sales);
dispComm(sales);
calcTotal(sales);
dispTotal(sales);
system("pause");
return 0;
}
double getSales(double sales)
{
cout << "Enter sales amount: ";
cin >> sales;
return sales;
}
double calcComm(double sales)
{
double comm= (sales * .10);
return comm;
}
void dispComm(double comm)
{
cout << "Commission: $";
}
double calcTotal(double comm, double sales)
{
double total= (comm+sales);
return total;
}
void displayTotal(double total)
{
cout << "Total: $";
}
|
Your functions calculate things and return those values they have calculated. You are ignoring the returned values.
Here is how to actually get the returned value.
double theReturnedValue = getSales(sales);
or
comm = calcComm (sales);
, for example.
You need to learn: functions (
http://www.cplusplus.com/doc/tutorial/functions/ )
Last edited on
Topic archived. No new replies allowed.