I am running a loop 3 times, and each iteration has 3 decisions to make.
My problem occurs in my function 'calculateCharges'. The 'if' structure falls into 3 categories for the user to enter:
0 to 3
>3 to 10
>10 on
The problem seems to occur when I try to enter hours parked greater than 10 as seems to also be calling the >3 to 10 option as well, as shown by printing out:
"2nd one"
"3rd one"
where it should only print out "3rd one".
I am not sure if my 'if', 'else if', statements are being used right, but I've tried other combos and doesn't seem to work too well as it seems to give run-time errors. Can ideas?
----
// Enter hours parked for each car
// A car an park more than 10 hours, but it cannot be charged hire than the max fee
// $2.00 min parking fee for up to 3 hours
// $0.50 for each extra hour, or part thereof for each additional hour
// Calculate and print parking charges for each of 3 customers who parked their cars in the garage
// Calculate and print total of parking receipts
for (counter = 1; counter < 4; counter++) // later change to a variable, if possible, which can be set to how many you cars you want to enter
{
cout << "Enter the number of hours parked: ";
cin >> hours_parked;
fee_current = calculateCharges(hours_parked);
cout << "\nThis car parked " << fixed << setprecision(2) << hours_parked << " hour(s)." << endl;
cout << "\nCost for this car is $" << fixed << setprecision(2) << fee_current << endl;
cout << "\n\n" << endl;
fee_running = fee_running + fee_current; // charged fee for current car
//assign current charged fee of car to a static name to be printed later
if (counter == 1)
{ car_1 = fee_current; }