parking garage assignment

Hello I have been working on this code for days and I am having so much trouble.. I have no idea what I am doing and really appreciate any help I can get! Also if you could explain what I should do next, Thank you so much! so my assignment is...
A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for
any given 24-hour period is $10.00. People who park their cars for longer than 24 hours will pay $8.00 per day.
Write a program that calculates and prints the parking charges. The inputs to your program are the date and time when a car enters the parking garage, and the date and time when the same car leaves the parking garage. Both inputs are in the format of
YY/MM/DD hh:mm

errors are on line 13
error C2143: syntax error : missing ';' before '>>'
error C2371: 'std::cin' : redefinition; different basic types

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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;

string startDateString;
string endDateString;
string dateStr;
int std::cin >>;
int parseDate( std::string dateStr );

int main ()

{
int line;
int enter_date;
int enter_time;
int exit_date;
int exit_time;
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,line);//cin >> enter_date >> enter_time;

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,line);//cin >> exit_date >> exit_time;


{
    // 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;
}
int startTime = parseDate( startDateString );
int endTime   = parseDate( endDateString );
int elapsedTime = endTime - startTime; // elapsedTime is no. of minutes parked

return 0;
}
problem 1) line 13: int std::cin >>; what are you trying to do here?
problem 2) line 20: variable line is of type int, but "YY/MM/DD hh:mm" date is not in int format. It is a string format?
problem 3) line 24: you overwrite first entered variable line value. And loose time for car to enter parking.
problem 4) line 27: what "{" is doing here?
problem 5) line 48: you don't use variable elapsedTime.

you don't use variables
int enter_date;
int enter_time;
int exit_date;
int exit_time
Last edited on
I have no idea I got help with this earlier but if I take it out I get even more errors can you please help me fix it and explain how? I changed line 13 to int std::cin ; which got rid of one error but I am still lost with that, and I will change line 20 to a string.

umm I am really confused could you explain what is wrong with it?
Last edited on
Here you do not fix it, but you need to rewrite almost everything.

line 29 - 33: variable dateStr don't have any data in it. Your data is in variable line.
is there an easier way to do this because I really don't understand anything I have someone was helping me earlier but never explained it... I just started c++ and just can't get the hang of it
first you need to understand your assignment and write calculations on paper. Like math task.
Then look at what you get and what you need to do. Solve this task on the paper using mathematical formulas. Not programing.
Last edited on
I understand how to do the math I just don't understand how to program, and I have tried doing easier codes and working my way up but now my assignment is do in like two days and I am totally lost. I just need a simple way to do this. can you please just walk me through this? I do not even know where to start
Last edited on
Sorry don't look like it :(
but here part, to get elapsedTime.

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
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int parseDate(string);

int main ()
{
	string enter;
	int startDateMins;
	int endDateMins;
	int elapsedTime;
	
	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);//cin >> enter_date >> enter_time;
	
	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);//cin >> exit_date >> exit_time;
	
	endDateMins = parseDate(enter);
	
	elapsedTime = endDateMins - startDateMins;
	
	cout << elapsedTime;
	
	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;
}
Topic archived. No new replies allowed.