Logical problem
I'm to get an output of this:
From: 10:20:30
After: 15:45:40
Now is: 2:6:10
but what am getting is no way close to it
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include <iostream>
using namespace std;
class Time {
int hour;
int minute;
int second;
public:
Time(int x=0, int y=0, int z=0)
{
hour = x;
minute = y;
second = z;
}
int getHour() {
return hour;
}
int getMinute() {
return minute;
}
int getSecond() {
return second;
}
Time add(Time &t);
void input()
{
cin >> hour >> minute >> second;
}
void output()
{
cout << hour << ":" << minute << ":" << second << endl;
}
};
Time Time::add(Time& t) {
int newhour, newminute, newsecond;
newhour = hour + t.hour;
newminute = minute + t.minute;
newsecond = second + t.second;
Time time(newhour,newminute,newsecond);
return time;
}
int main() {
Time myTime(10,20,30), newTime(15,45,40);
cout << "From: ";
myTime.output();
cout << "After: ";
newTime.output();
cout << "Now is: ";
Time now = myTime.add(newTime);
now.output();
return 0;
}
|
1 2 3 4 5 6 7 8 9
|
Time(int x=0, int y=0, int z=0)
{
hour = x;
minute = y;
second = z;
while ( second >= 60 ) { minute++; second -= 60; }
while ( minute >= 60 ) { hour++ ; minute -= 60; }
hour %= 24;
}
|
But Lastchance its not giving me the right output
It gives
From: 10:20:30
After: 15:45:40
Now is: 2:6:10 |
What would you like?
Ohh
sorry Lastchance just figured what you were saying now
Thanks.
Can I private chat you
@Learner1, I'd think you'd be better putting questions in the open forum: you will get more and better answers.
I know but it's just for some personal purpose
Topic archived. No new replies allowed.