help with Time Class

Hey guys,

So this is the problem I'm tackling:
Create 2 Time Objects.
1 Time object should be instantiated using the default constructor.
1 Time object should be instantiated using the constructor that requires hours, minutes and seconds. Read data from keyboard.
Find the difference in hours, minutes and seconds between the two Time objects.

Now!
to create the first time object I use

Time timeOne ();

for the second one I thought I needed to declare one which gave me:
Time timeTwo (int h, int m, int s);

is that wrong?
I was thinking about asking for user input and setting it...as in:
1
2
3
4
5
6
7
cout << "Enter hour" << endl;
cin >> hours;
cout << "Enter minutes" << endl;
cin >> minutes;
cout << "Enter seconds" << endl;
cin >> seconds;
timeTwo.set_Time (int hours, int minutes, int seconds);


but it is coming out as an error....

for the comparing the hours and minutes, etc I'm planning on using
timeOne.hours_from(timeTwo);

what am I doing wrong?
Tell us your error....there could be multiple differnet things that could be wrong....also you will probably need to show all code
Sorry the error reads
"error: expected primary-expression before 'int'"

the entire code is:

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
#include <iostream>
using namespace std;

#include "ccc_time.h"
#include "ccc_empl.h"
#include "ccc_time.cpp"
#include "ccc_empl.cpp"
#include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <ctime>

//Function Prototypes




//  main function **********************************************************
int main ()
{

//create timeone via default constructor
//create timetwo via user input
Time timeOne ();
Time timeTwo (int h, int m, int s);
int hours, minutes, seconds;

cout << "Enter hour" << endl;
cin >> hours;
cout << "Enter minutes" << endl;
cin >> minutes;
cout << "Enter seconds" << endl;
cin >> seconds;

timeTwo.set_Time (int hours, int minutes, int seconds);


//Create function to find difference in hours, minutes, and seconds between
//  the two times.
//Declare minuteone, minutetwo, etc,etc
//Display:
//	a. timeone
//	b. timetwo
//	c. difference between the two times


	// End of program statements
	cout << "Please press enter once or twice to continue...";
	cin.ignore().get();    			// hold console window open
	return EXIT_SUCCESS;           	// successful termination
}
What line, is that the entire code?
i'm not sure if this is a problem but you do have iostream twice...
#include <iostream> ? No
Line 25 does not call the default constructor for the Time class. Instead it is a function prototype for a function called timeOne() which returns a Time object. To instantiate an object using the default constructor leave off the parenthesis. Change line 25 to:
Time timeOne;

Similarly, line 26 is a function prototype. It should not have the int before each variable. In addition you need to instantiate it after you have obtained the values from the user, so move line 26 after line 34 and call the constructor using the variables hours, minutes and seconds which have just been initialized from the user:
Time timeTwo( hours, minutes, seconds );

Line 36 also should not have the type int in front of the variable names in your call of the member function set_Time(). But that whole line shouldn't be necessary since timeTwo should have been set to the user generated values in the constructor for timeTwo, so eliminate line 36: timeTwo.set_Time (int hours, int minutes, int seconds);
i'm not sure if this is a problem but you do have iostream twice...

Not a problem. Any implementation of that header will have multiple inclusion guards.
Topic archived. No new replies allowed.