#include <cstdlib>
#include <iostream>
#include <math.h>
usingnamespace std;
int main(int argc, char *argv[])
{
int cars = 0;
int userChoice;
constint flatRate = 6;
constdouble hourlyFee = 2.50;
double customerFee = 0;
int carHours;
...
cout << " Do you want to exit? if so enter -1 if enter any key" << endl;
cin >> userChoice;
if (userChoice != -1)
{
cars += 1;// record ammount of cars input into program
cout << cars << endl;
}
}
while (userChoice != -1);
cout << " The total number of Cars for today was: " << cars << endl;
cout << "Have a nice Day" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Then when you increment the number of cars (line58?):
totalCost+=customerFee;
edit: i would also initialise your 'customerFee' to zero at the very top of your do while loop (before your first if statement for example), rather than outside.
mutexe can i ask one more question the program is not receiving the last car ( if i get the price of 4 cars it only registers up until 3 and disregards 4) is it a matter of moving car+=1 ?
pretty much yes. As you can see on line 56 if the user enters -1 the last car is not added.
you may as well do the increment as soon as you're in the do while loop i think.
edit: actually, delete lines 56, 57 and 60. That should do it.
// increment number of cars
cars++;// record amount of cars input into program
cout << "Enter q to quit, or any other key to enter a new car" << endl;
cin >> userChoice;
} while (userChoice != 'q');