Parking garage hours for vehicles and the charge for them

Write your question here.


Here is the code
This is what i have so far

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setw;
using std::setprecision;
int main()
{
int count;
int x;
double charge;
double a;
double b;
double c;
cout<< "Enter the number of Hours: ";
cin >> a >> b >> c;
cout<< setw(5)<< "Car" << setw(10)<< "Hours" << setw(15)<< "Charge\n";
cout << fixed << setprecision (2);
count = 1;
while ( count <=3 ) {
if (count == 3)
x = c;
else if (count == 2)
x = b;
else if (count == 1)
x = a;
if (x <= 3)
charge = 2;
else if (x >19)
charge = 10;
else if (x > 3)
charge = 2 + (x - 3) * (.5);
cout <<setw(5) << count<< setw(10) << x << setw(10)<< "$"<<charge <<"\n";
count = count + 1;}
return 0;
}



My question is how would i put in the total of hours for the vehicles and the total hours for the garage for the vehicles of input...
set like this

Car Hours Charge
1 1.5 2.00
2 4.0 2.50
3 24.0 10.00
Total 29.5 14.50 <---This is what i need for my code still
Please use code tags when posting code here, to make it readable.

You'll need to add some new variables to store the running totals for hours and charge. Then, as you loop through your vehicles, you need to update those running totals for each vehicle in turn.

By the way, your code will be much simpler if you simply use an array to hold the values entered by the user. You won't need to do all that messy business of setting x to a, b, or c depending on the value of count. You'll be able to simply access each array element using the loop index.
Last edited on
Topic archived. No new replies allowed.