The way your functions are defined is invalid. The variables need to be defined when being used as parameters for the function. Also your check for the Sale ID only implemented after the first time the loop ran. Here is modified version of your code that is working. I added a few comments where the changes are not very drastic.
/*
* Pass6
*/
/* People get paid a base salary, plus a percentage of all sales over the base sales amount.
1) Read 3 digit salesman ID number, a float base salary and sales amount for each category.
2) Using a function, compute the commission earned in each category.
3) Print the ID number and base salary.
4) For each category, print description, sales amount, and commission amount.
5) Print total commission paid to the employee and total paid.
6) Continue looping until -999 is inputted for Salesman Number.
*/
#include <iostream>
#include <iomanip>
using namespace std;
/* Universal Floats */
float totalPcCom, totalMemCom, totalZipCom, totalPrintCom, baseSalary, pcSales, memCardSales, zipDriveSales, printerSales, totalCommission;
/* Function Prototype */
// No need for the line below as it is handled by the next function.
//double calcComm(float pcSales, float memCardSales, float zipDriveSales, float printerSales);
double calcCommission (float pcSales, float memCardSales, float zipDriveSales, float printerSales)
{
/* Check and see if salesman gets commission from PCs*
If so, commission is calculated. If not, commission
is left at zero. */
if (pcSales>=4000)
totalPcCom = (pcSales - 4000) * .10;
else
totalPcCom = 0;
/* Check and see about other commissions */
if (memCardSales>=1000)
totalMemCom = (memCardSales - 1000) * .05;
else
totalMemCom = 0;
if (zipDriveSales>=800)
totalZipCom = (zipDriveSales - 800) * .04;
else
totalZipCom = 0;
if (printerSales>=2000)
totalPrintCom = (printerSales - 2000) * .08;
else
totalPrintCom = 0;
return (totalPcCom, totalMemCom, totalZipCom, totalPrintCom);
}
int main ()
{
/* Everything has to be in a loop!!!! */
int salesID;
do
{
/* Output for 3 digit salesman ID number, float base salary and sales amount for each category. */
cout << "Please Enter Salesman ID number or -999 to terminate: " << endl;
cin >> salesID;
if (salesID == -999)
break;
cout << "Please Enter Base Salary: " << endl;
cin >> baseSalary;
cout << "Please Enter Personal Computer Sales: " << endl;
cin >> pcSales;
cout << "Please Enter Memory Card Sales: " << endl;
cin >> memCardSales;
cout << "Please Enter Zip Drive Sales: " << endl;
cin >> zipDriveSales;
cout << "Please Enter Printer Sales: " << endl;
cin >> printerSales;
/* Function and Computation Time!!! */
//Call the calcCommission function instead of calcComm
totalCommission = calcCommission (pcSales, memCardSales, zipDriveSales, printerSales);
/* Displaying the information for the current salesman */
cout << "Saleman ID # " << salesID << endl;
cout << "Base Salary: " << baseSalary << endl;
cout << "Total PC Commission: " << totalPcCom << endl;
}
/* Checking again if id!=-999 */
while (salesID!=-999);
}
/*
* Pass6
*/
/* People get paid a base salary, plus a percentage of all sales over the base sales amount.
1) Read 3 digit salesman ID number, a float base salary and sales amount for each category.
2) Using a function, compute the commission earned in each category.
3) Print the ID number and base salary.
4) For each category, print description, sales amount, and commission amount.
5) Print total commission paid to the employee and total paid.
6) Continue looping until -999 is inputted for Salesman Number.
*/
#include <iostream>
#include <iomanip>
using namespace std;
/* Universal Floats */
float totalPcCom, totalMemCom, totalZipCom, totalPrintCom, baseSalary, pcSales, memCardSales, zipDriveSales, printerSales, totalCommission;
/* Function Prototype */
// No need for the line below as it is handled by the next function.
//double calcComm(float pcSales, float memCardSales, float zipDriveSales, float printerSales);
double calcCommission (float pcSales, float memCardSales, float zipDriveSales, float printerSales)
{
/* Check and see if salesman gets commission from PCs*
If so, commission is calculated. If not, commission
is left at zero. */
if (pcSales>=4000)
totalPcCom = (pcSales - 4000) * .10;
else
totalPcCom = 0;
/* Check and see about other commissions */
if (memCardSales>=1000)
totalMemCom = (memCardSales - 1000) * .05;
else
totalMemCom = 0;
if (zipDriveSales>=800)
totalZipCom = (zipDriveSales - 800) * .04;
else
totalZipCom = 0;
if (printerSales>=2000)
totalPrintCom = (printerSales - 2000) * .08;
else
totalPrintCom = 0;
return (totalPcCom, totalMemCom, totalZipCom, totalPrintCom);
}
int main ()
{
/* Everything has to be in a loop!!!! */
int salesID;
do
{
/* Output for 3 digit salesman ID number, float base salary and sales amount for each category. */
cout << "Please Enter Salesman ID number or -999 to terminate: " << endl;
cin >> salesID;
if (salesID == -999)
break;
cout << "Please Enter Base Salary: " << endl;
cin >> baseSalary;
cout << "Please Enter Personal Computer Sales: " << endl;
cin >> pcSales;
cout << "Please Enter Memory Card Sales: " << endl;
cin >> memCardSales;
cout << "Please Enter Zip Drive Sales: " << endl;
cin >> zipDriveSales;
cout << "Please Enter Printer Sales: " << endl;
cin >> printerSales;
/* Function and Computation Time!!! */
//Call the calcCommission function instead of calcComm
totalCommission = calcCommission (pcSales, memCardSales, zipDriveSales, printerSales);
/* Displaying the information for the current salesman */
cout << "Saleman ID # " << salesID << endl;
cout << "Base Salary: " << baseSalary << endl;
cout << "Total PC Commission: " << totalPcCom << endl;
}
/* Checking again if id!=-999 */
while (salesID!=-999);
}