# Problem with functions

This topic is 4345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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);

##### Share on other sites
bakery2k1, you nailed it friend. I can't thank you enough; you'll get an excellent rating from me! It's such a great resource to have all of you on here when I need help.

Did anyone else have a little trouble with functions as a beginning programmer? I'm trying to gauge whether I can ever be productive in this field or not. My plan is to get into graphics eventually, and then games.

##### Share on other sites
When I was a beginner, I had trouble with everything. If you're a beginner, I'd advise you to stubbornly stick with it for at least a year or two, before trying to decide if you'd be good at it. It does get easier with constant practice, like most things.

##### Share on other sites
Thanks for that feedback, LastUnicron; it helps me feel a bit better. Sometimes I've wondered if I should be catching onto this stuff easier than I am.

##### Share on other sites
Well it wans't possible for me to run into that error, when using pascal all variables are global (Except those defined under a function/procedure but a beginner wouldn't know he could declare it in that local scope) and thus techinically this misunderstanding could not have occured!

##### Share on other sites
When i was first starting C++, everything was frustrating. Everything. It's like hiking uphill through a dense forest. You don't think you are making any progress until you reach a clear spot at the top and think "wow, you can see everything from up here!"

##### Share on other sites
It took me one year to be able to compile K&R Hello world example using MS QuickC 5.1 back then, on my dad's 8088 XT.