Parking Garage

I have a program where a parking garage charges 6 dollars for 3 hours. for extra hours, they charge an extra 2.50. for a 24 hour period they charge 35 dollars. i have my code and it runs but still gets the calculations kind of wrong.
What is the right formula to calculate the extra cost if it goes over 3 hours?
What is the right formula to get the 24 hours to set to 35 dollars?
what is the right formula to calculate if it goes over 25 hours?
How can i set a for loop?

My code:

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

int main ()
{
int hOurs = 0;
float chrGe, exchRge, pchgrGe;
double total, chArge = 6.00, extrachArge = 2.50, periodchA = 35.00;


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



if(hOurs <= 3)
{
total = chArge;
}
else if( hOurs >= 3)
{
total = (chArge - hOurs + 3)* extrachArge;
}
else if(hOurs >= 24)
{
total = periodchA;
}


cout << "Your total charge is: $" << total << endl;


system("pause");
return 0;

}
You shouldn't double post.
http://www.cplusplus.com/forum/beginner/144580/
It makes it harder on those that try to help, not knowing what someone else is has or has not shown or told you.
*considering that every 24 hours is replaced with $35, and that there is no $6 for the start after 24 hours.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <math.h>  
#include <string> //its not really used for the math

int main()
{
  double num_hours = 0;
  double cost = 0;
  
  std::cout << "Number of hours beging parked: ";
  std::cin >> num_hours;
    
  if(num_hours <= 3) 
  {
      cost = 6; 
  } else if(num_hours >= 24) {
      cost = ((num_hours - remainder (num_hours , 24)) / 24) * 35; 
      cost += ( remainder (num_hours , 24) ) *2.5;
      
  } else {
      cost = 6;
      cost += (num_hours - 3) * 2.5;
  }
  
  std::cout<<"\nThat will cost: "<<cost<<"\n";
  
  //pause
  std::cout<<"Press enter to continue... \n";
  std::string s; 
  std::getline(std::cin.ignore(),s);
  
  return 0;
}
Last edited on
thanks for the help
Topic archived. No new replies allowed.