Original Post
Hello all. If one of you can help me with this I'll be indebted for life. I really want to become a programmer but am having some trouble understanding functions and getting them to work. For whatever reason the following program I've written isn't calculating correctly, and I can't figure out why for the life of me. Can someone help? The program is supposed to calculate a car salesman's paycheck based on his # of sales of a particular model plus commission. I've declared both the model of car and commission rate as global variables at the top of the program, as you can see. Everything compiles okay but the paycheck amount is way off for every input that is given. Can someone tell me or at least clue me in on what could be causing the calculation problem? Thanks!
#include <iostream>
#include <cstdlib>
using namespace std;
float experience();
float pay(float);
float commission();
//Declare global variables for program
const float Autorust = 17000.00, Belchfire = 30000.00, Turbosmog = 49000.00;
const float AutorustComm = .03, BelchfireComm = .05, TurbosmogComm = .08;
int main()
{
//Declare variables for program input & output
int AutorustNo, BelchfireNo, TurbosmogNo;
float basePay, yearsExp, totalComm, paycheck;
//Prompt user for input and perform calculations through functions
experience();
commission();
paycheck = basePay + totalComm;
cout << fixed << showpoint << setprecision(2);
cout << endl << "Paycheck amount is: " << "$" << paycheck << endl;
system("pause");
return 0;
}
float experience()
{
float yearsExp;
cout << "Enter the number of years of experience: ";
cin >> yearsExp;
pay(yearsExp);
}
float pay(float worked)
{
float basePay;
if (worked >= 2)
basePay = 25000.00;
else
basePay = 18000.00;
return basePay;
}
float commission()
{
int AutorustNo, BelchfireNo, TurbosmogNo;
float totalComm;
cout << endl << "Enter the number of Autorust models sold: ";
cin >> AutorustNo;
cout << endl << "Enter the number of Belchfire models sold: ";
cin >> BelchfireNo;
cout << endl << "Enter the number of Turbosmog models sold: ";
cin >> TurbosmogNo;
totalComm = (AutorustComm * AutorustNo * Autorust) +
(BelchfireComm * BelchfireNo * Belchfire) +
(TurbosmogComm * TurbosmogNo * Turbosmog);
return totalComm;
}