hhaysMr_Gbg wrote:
return salesAmount, commissionRate, totalBonus;
You cannot return
3
values from a
C++
function (only a value is allowed).
Code compiles because the comma operator discards all the values but the last.
A simple solution would be passing the three parameters by reference:
void getDataz(double & salesAmount, double & commissionRate, double & totalBonus)
{
cout << "\n\n\nPlease enter the sales amount:";
cin >> salesAmount;
if (salesAmount < 20000) commissionRate = .04;
else if (salesAmount >= 20000 && salesAmount < 30000) commissionRate = .05;
else if (salesAmount >= 30000 && salesAmount < 40000) commissionRate = .06;
else if (salesAmount >= 40000 && salesAmount < 50000) commissionRate = .07;
else if (salesAmount >= 50000) commissionRate = .09;
totalBonus = salesAmount * commissionRate;
}
[update]
This program
#include <iostream>
using namespace std;
void description();
void getDataz(double & salesAmount, double & commissionRate, double & totalBonus);
int printDataz(double salesAmount, double commissionRate, double totalBonus);
int main()
{
double salesAmount, commissionRate, totalBonus;
cout << "main entered";
description();
cout << "description called";
getDataz(salesAmount, commissionRate, totalBonus);
cout << "getdataz called";
printDataz(salesAmount, commissionRate, totalBonus);
cout << "printdataz called";
return 0;
}
void description()
{
cout << "This program will calculate the commission rate and total bonus "
<< "for an associate's sales";
return;
}
void getDataz(double & salesAmount, double & commissionRate, double & totalBonus)
{
cout << "\n\n\nPlease enter the sales amount:";
cin >> salesAmount;
if (salesAmount < 20000) commissionRate = .04;
else if (salesAmount >= 20000 && salesAmount < 30000) commissionRate = .05;
else if (salesAmount >= 30000 && salesAmount < 40000) commissionRate = .06;
else if (salesAmount >= 40000 && salesAmount < 50000) commissionRate = .07;
else if (salesAmount >= 50000) commissionRate = .09;
totalBonus = salesAmount * commissionRate;
}
int printDataz(double salesAmount, double commissionRate, double totalBonus)
{
cout << "\n\nThe commission rate for $"<<salesAmount<<" is: " << commissionRate<<endl;
cout << "The total bonus is: $"<<totalBonus;
system("pause");
return 0;
}
produces the following, on my system (
Windows 7
,
Visual Studio 2010
):
main enteredThis program will calculate the commission rate and total bonus for
an associate's salesdescription called
Please enter the sales amount:100
getdataz called
The commission rate for $100 is: 0.04
The total bonus is: $4Press any key to continue . . .
[/update]
:)