if else

So i am almost done with my program I just need to print the correct amount for the case that the entering and leaving dates are in different months. I am not sure if I can use an if statement for that? Thank you in advanced for all of the help!!

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int parseDate(string);

int main ()
{
	string enter;
	int startDateMins;
	int endDateMins;
	int elapsedTime=0;
	
	cout << "Please enter the date and time the car is entering "<< endl
		<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
	getline (cin, enter);
	startDateMins = parseDate(enter);
	
	cout<< "Please enter the date and time the car is exiting "<< endl
		<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
	getline (cin, enter);
	
	endDateMins = parseDate(enter);
	
	elapsedTime = endDateMins - startDateMins;
	
	if (elapsedTime<=180)
cout << "Parking fee due:$2.00"<<endl;
	else if (elapsedTime>180 && elapsedTime <=240)
		cout<< "Parking fee due: $2.50"<<endl;
	else if (elapsedTime> 240 && elapsedTime<=300)
		cout<< "Parking fee due: $3.00"<<endl;
	else if (elapsedTime>300 && elapsedTime <=360)
		cout<< "Parking fee due: $3.50"<<endl;
	else if (elapsedTime>360 && elapsedTime<=420)
		cout<<"Parking fee due: $4.00"<<endl;
	else if (elapsedTime>420 && elapsedTime<=480)
		cout<<"Parking fee due: $4.50"<<endl;
	else if (elapsedTime>480 && elapsedTime<=540)
		cout<<"Parking fee due: $5.00"<<endl;
	else if (elapsedTime>540 && elapsedTime<=600)
		cout<<"Parking fee due: $5.50"<<endl;
	else if (elapsedTime>600 && elapsedTime <=660)
		cout<< "Parking fee due: $6.00"<<endl;
	else if (elapsedTime> 660 && elapsedTime<=720)
		cout<< "Parking fee due: $6.50"<<endl;
	else if (elapsedTime>720 && elapsedTime <=780)
		cout<< "Parking fee due: $7.00"<<endl;
	else if (elapsedTime>780 && elapsedTime<=840)
		cout<<"Parking fee due: $7.50"<<endl;
	else if (elapsedTime>840 && elapsedTime<=900)
		cout<<"Parking fee due: $8.00"<<endl;
	else if (elapsedTime> 900 && elapsedTime<=960)
		cout<< "Parking fee due: $8.50"<<endl;
	else if (elapsedTime>960 && elapsedTime <=1020)
		cout<< "Parking fee due: $9.00"<<endl;
	else if (elapsedTime>1020 && elapsedTime<=1080)
		cout<<"Parking fee due: $9.50"<<endl;
	else if (elapsedTime>1080 && elapsedTime<=1140)
		cout<<"Parking fee due: $10.00"<<endl;
	else if (elapsedTime>=1440)
		cout<<"Parking fee due:$8.00"<<endl;
	else if (elapsedTime>=1440
	return 0;
}

int parseDate(string dateStr)
{
	// Format: YY/MM/DD hh:mm
  int year  = atoi( dateStr.substr( 0, 2 ).c_str() );
  int month = atoi( dateStr.substr( 3, 2 ).c_str() );
  int day   = atoi( dateStr.substr( 6, 2 ).c_str() );
  int hour  = atoi( dateStr.substr( 9, 2 ).c_str() );
  int min   = atoi( dateStr.substr( 12, 2 ).c_str() );
  
  // Now calculate no. of mins and return this
  int totalMins = 0;
  totalMins += ( year * 365 * 24 * 60 ); 
  totalMins += ( month * 30 * 24 * 60 ); 
  totalMins += ( day * 24 * 60 );        
  totalMins += ( hour * 60 );
  totalMins += ( min );
	
  return totalMins;
}
:D :D :D
And you said you know how to calculate on paper.
:D :D :D

If I leave car for 2 years, I will pay only $8.00. It's very cheap.

P.S.
It means you can't use if-else. You need to calculate fee like in math. Using math formulas. Where time is x.
I do know how to do the math! What I do not know is how to put it in code. I also understand that it only works for 24hrs that is why I was asking for help so it will be in a different month or for more than 1 day. I would really appreciate any guidance with this. Thank you
my question.
atoi( dateStr.substr( 0, 2 ).c_str() )
do you know what that does?
Converts string to integer
Show to me how you do it on paper.
As I said you need a function like
f()=2d+3m-2
d - days; m - mins.
Okay, think I got it thank you so much for all of the help:)
It is good that you understand :D
Topic archived. No new replies allowed.