Error in calculation of time. Pls help! urgent!

This is for an assignment given by our teacher. The question is to write a program to add two time objects.
Here's what I did:
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
#include<iostream.h>
#include<conio.h>
class Time
{
public:
int hours,minutes,seconds;
void GetTime()
{
cout<<"Enter Hours:";
cin>>hours;
cout<<"Enter Minutes :";
cin>>minutes;
cout<<"Enter Seconds:";
cin>>seconds;
}
void PutTime()
{
cout<<hours<<" Hours "<<minutes<<" Minutes "<<seconds<<" Seconds\n\n";
}
void add(Time t)
{
Time Sum;
int a,b;
a=(t.seconds+seconds)/60;
Sum.seconds=(t.seconds+seconds)%60;
b=(t.minutes+minutes+a)/60;
Sum.minutes=(t.minutes+minutes+a)%60;
Sum.hours=(t.hours+hours+b);
cout<<Sum.seconds<<" : "<<Sum.minutes<<" : "<<Sum.seconds;
}
};
void main()
{
clrscr();
Time t1,t2;
cout<<"\nEnter details for time 1 :\n";
t1.GetTime();
cout<<"\nEnter details for time 2 :\n";
t2.GetTime();
cout<<"\nTime 1 :\n";
t1.PutTime();
cout<<"\nTime 2 :\n";
t2.PutTime();
t2.add(t1);
getch();
}


There's an error in sum of hours in the output. Pls help very urgent
Line 29. What do you think are you doing?
MiiNiPaa I am just outputting the sum of both the time objects.
What exactly you are outputting? step by step, quoting parts of your line and expaining what it is for.
i'll tell you.
1
2
3
4
5
6
7
8
cout<<"\nEnter details for time 1 :\n";
t1.GetTime();
cout<<"\nEnter details for time 2 :\n";
t2.GetTime();
cout<<"\nTime 1 :\n";
t1.PutTime();
cout<<"\nTime 2 :\n";
t2.PutTime();

this is for inputting two sets of hours, miuntes,seconds.
ok?
1
2
3
4
5
6
7
8
9
10
11
void add(Time t)
{
Time Sum;
int a,b;
a=(t.seconds+seconds)/60;
Sum.seconds=(t.seconds+seconds)%60;
b=(t.minutes+minutes+a)/60;
Sum.minutes=(t.minutes+minutes+a)%60;
Sum.hours=(t.hours+hours+b);
cout<<Sum.seconds<<" : "<<Sum.minutes<<" : "<<Sum.seconds;
}

this is for adding both the hours, both the minutes, both the seconds.
get it?

I am asking you about single line:
cout<<Sum.seconds<<" : "<<Sum.minutes<<" : "<<Sum.seconds;
Explain meaning of each parameter.
Topic archived. No new replies allowed.