I have a tiny prob with this piece of code . I want the program to compute fees for each car separately store it somewhere and then display the table will all result . the problem is that I don't now were to put the charges each time then display all of them together . the prog is displaying on each loop how can I modify that to work as I expected .
thanksCode:
double calculate_charges ( double h ) {
if ( h == 24 ) {
return 10.00;
}
else if ( h <= 3 ) {
return 2.00;
}
else {
double chg = 3 + (( h - 3 ) *0.50);
return chg;
}
}
int main () {
int x; double hours;
do {
cout << "Please enter the number of cars :\n" << endl;
cin >> x;
}while ( x <= 0 && cout <<"Wrong choice!" );
for ( int i = 1 ; i <= x ; ++i ) {
do {
cout << "\nPlease enter the number of hours parked by car " << i << " today :\n" << endl;
cin >> hours;
}while ( hours > 24 && cout << "Wrong choicde! " );
for ( int j = 1 ; j <= i ; j++ )
cout <<"\n"; added this in order to separate them so you can see what the problem try to compute it like this
cout << "Car\t\tHours\t\tCharge\n"
<< "----\t\t------\t\t-------" << endl
<< i <<"\t\t"<< hours << "\t\t" << calculate_charges ( hours ); // this function is out the main .
}
system ( " pause " );
return 0;
}