Hi there.
I've made a C++ program which reads the time (input by the user) and adds two times entered using the concept of classes. However the answer always comes 11 hours 10 minutes regardless of what I enter. I don't understand what's wrong..
Code:
class Clock
{
private:
unsigned int HOUR, MIN;
public:
void Readtime(int h, int m);
void Showtime(); //Display data members
void Addtime(Clock T1, Clock T2);
};
void Clock :: Readtime(int h, int m)
{
Clock Temp;
cout << "\nEnter hours : ";
cin >> h;
cout << "\nEnter minutes : ";
cin >> m;
Temp.HOUR = h;
Temp.MIN = m;
}
void Clock :: Showtime()
{
Clock T;
while(T.MIN > 60)
{
T.MIN -= 60;
T.HOUR++;
}
while(T.HOUR > 24)
{
T.HOUR -= 24;
}
cout << "\nThe time you entered is " << T.HOUR << " hours and " << T.MIN << " minutes";
cout << "\nThe time is as per 24 hour clock";
}
void Clock :: Addtime(Clock T1, Clock T2)
{
Clock Temp;
Temp.HOUR = T1.HOUR + T2.HOUR;
Temp.MIN = T1.MIN + T2.MIN;
}
int main()
{
Clock FT, ST, Use;
int H, M;
FT.Readtime(H, M);
ST.Readtime(H, M);
Use.Addtime(FT, ST);
Use.Showtime();
getch();
}
Edit : Nevermind, I have solved the problem.