Logical Error in Clock program

This is a discussion on Logical Error in Clock program within the C++ Programming forums, part of the General Programming Boards category; Hi there. I've made a C++ program which reads the time (input by the user) and adds two times entered ...

  1. #1
    Cryptanalyst
    Join Date
    Sep 2007
    Posts
    52

    Logical Error in Clock program

    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.
    Last edited by SVXX; 05-10-2009 at 02:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21