|
-
July 27th, 2012, 01:27 AM
#1
will you help me plz ...i didn't get the right o/p
This is the program for add two times
#include<iostream.h>
#include<conio.h>
class time
{
long int hr,min,sec;
public:
void get();
void put();
void add(time t1,time t2);
time();
};
time::time()
{
hr=0;
min=0;
sec=0;
}
void time::get()
{
cout<<"enter the time in hours,minuts and seconds:";
cin>>hr>>min>>sec;
}
void time: ut()
{
cout<<"\nthe time:"<<hr<<":"<<min<<":"<<sec;
}
void time::add(time t1,time t2)
{
time s;
s.sec=(t1.sec+t2.sec);
if(s.sec>=60)
{
s.sec=s.sec%60;
s.min++;
}
s.min=(s.min+t1.min+t2.min);
if(s.min>=60)
{
s.min=s.min%60;
s.hr++;
}
s.hr=(s.hr+t1.hr+t2.hr);
}
void main()
{
clrscr();
time t1,t2,t3;
t1.get();
t2.get();
t3.add(t1,t2);
t1.put();
t2.put();
cout<<"\nsum:";
t3.put();
getch();
}
the compiler shows no error, but
the output that i got is always:0 0 0
Last edited by fasluca; July 31st, 2012 at 11:25 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|