# can't work out float???

This is a discussion on can't work out float??? within the C++ Programming forums, part of the General Programming Boards category; Hi everyone! /* A program that calculates and print the parking charges for each of 3 customers who parked their ...

1. ## can't work out float???

Hi everyone!

/* A program that calculates and print the parking charges for each of 3 customers who parked their car in the garage yesterday
*/

#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

int main()
{
float hours,
totalHour = 0,
totalCharge = 0;

float calculateCharges(float);

for(int a = 1; a < 4; a++) {
cout << setw(9) << ":";
cin >> hours;
cout << a << setw(10) << hours << "h" << setw(8) << "\$"
<< calculateCharges(hours)
<< endl << endl;
totalHour += hours;
totalCharge += charges; //[B]THIS IS WHAT I TRIED. NO GOOD[B]

//[B] I GET --UNDERFINED SYMBOL IN FUNCTION MAIN--- ERROR[B]
}

cout << "TOTAL" << setw(7) << totalHours;
return 0;
}

float calculateCharges(float h) {

float charges;

if (h <= 3) {
charges = 2;
return charges;
}
else
if (h >= 19) {
charges = 10;
return charges;
}
else
return charges = (h-3)*.50 + 2;
}

cout << "Cars" << setw(9) << "Hours" << setw(12)
<< "Charges" << endl;
cout << "----" << setw(9) << "-----" << setw(12) << "-------"
<< endl;
}

I have managed to do what it has asked me to do. The only that is wrong with it is that I CAN'T GET THE TOTAL FOR THE CHARGES.

Can someone help me, what should I do?
I tried doing the same for what I did with [B]totalHours[B] but it doesn't work. I get an error message ---Underfined symbol in function main---

2. > totalCharge += charges; //[B]THIS IS WHAT I TRIED. NO GOOD[B]

That's because you haven't declared charges in main. charges is only declared in the calculateCharges function, so it's out of scope in main.

Here's how I'd do it:
Code:
```int main()
{
float hours,
totalHour = 0,
totalCharge = 0,
charges;

float calculateCharges(float);

for(int a = 1; a < 4; a++) {
cout << setw(9) << ":";
cin >> hours;
charges = calculateCharges(hours);  //Might as well use the return value, since you've declared it.
cout << a << setw(10) << hours << "h" << setw(8) << "\$"
<< charges<< endl << endl;
totalHour += hours;
totalCharge += charges;
}

cout << "TOTAL" << setw(7) << totalHours;
return 0;
}```

3. ## Many thanks :)

Thanks Govtcheez!!!

I hate it when I can't figure out simple problems.

and thanks to everyone else too

I just wanna take this opportunity to say thanks to everybody who help out. I just love this site. I mean if you have a sincere problem and u are completely stuck with nowhere to go to ask for help you can always 100% rely on the very nice people that is willing to help out if they can.
There are some really great people out there who has gotten me out of jams that I would still be stuck in if it won't for them

Many thanks again!!!

4. Code:
```float calculateCharges(float);