charges

what variables do i use so that is the user chooses no they will display total amount of cars, total amount for all cars, and average charge per car?


#include <iostream>
#include <math.h>
#include <string>
using namespace std;

int main ()
{
double hOurs = 0;
double chrGe = 0;
int cHoice;

do
{


cout << "Please enter number of hours parked: ";
cin >> hOurs;


if(hOurs <= 3)
{
chrGe = 6;
}
else if(hOurs >= 24)
{
chrGe = ((hOurs - remainder (hOurs, 24)) / 24)* 35;
chrGe += (remainder (hOurs, 24))* 2.5;
}
else
{
chrGe = 6;
chrGe += (hOurs - 3)* 2.5;
}

cout << "Summary: " << endl;
cout << "Number of hours: " << hOurs << endl;
cout << "Total charged: $" << chrGe << endl;

cout << "Charge next car (1 for yes, 2 for no) ?";
cin >> cHoice;

}while (cHoice == 1);

if(cHoice = 2)
{





system("pause");
return 0;

}
Last edited on
You could've just asked that question in the last post you made...
When I made this for you, I honestly thought that it doesn't matter to show the amount of hours because you already inputted them...
I am highly disgusted that you put back system("pause");, made the variable names weird again(unusual capital letters), and that you still didn't remove #include <string> which i used to pause the program...You are not using int userChoice;, you are using namespace std(nitpick), and you didn't format your code.

Make another variable called double tempHours = hOurs; after the cin. and replace all occurrences of hOurs in the algorithms to tempHours and at the end just cout the original hOurs

And for the question... cin for the amount of cars. #include <vector> , and do a for statement for the amount of cars used, do a cin inside the for statment, and push back that value to a vector array. Do: for(auto it = carsVec.begin();it!=carsVec.end();it++){/*...*/}, do the math stuff inside of the loop, and replace hOurs with (*it), change the single equal signs with +=, and that should be it.

Now since this is different then the last one, we have to count the hours differently(forget the paragraph behind the last one), there is no tempHours, or hOurs, just Average, CarCount, TotalCost, TotalHours, and carsVec that stores the hours of the cars. At the end before the summary, do another loop of the carsVec, and do TotalHours += (*it);.

For the average do: Average = TotalHours / CarCount;
Last edited on
ok thanks. sorry im still a beginner
ok thamkyou
Topic archived. No new replies allowed.