Home Forums C Programming time input help

Viewing 1 reply thread
  • Author
    Posts
    • #2037
      malyn
      Participant

      hi guys,

      I am making a program in which I have to enter start date and time and stop date and time in format like 01:05:07 15:26:57

      i don’t know how to get that value from the user in hh:mm:ss format and calculate the difference between different inputs. i have no clue of that. could you guys give me some tips on that?

    • #3281
      Humayan
      Participant

      could try:
       

      /****************************************************************
      * File Name : c:programshelpshell.cpp
      * Date : November,29,2007
      * Comments : new project
      * Compiler/Assembler : VC++ 6.0
      * Program Shell Generated At: 2:34:45 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

      #include
      //#include
      //#include
      //#include
      //#include
      //#include
      using namespace std;

      //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
       void getTime ( int & hours , int & minutes , int & seconds );
      //##################################################################################

       //main function ******************************
      int main ( )
      {
         
          int hours , minutes , seconds;
         
          cout << "Enter a time: ";
          getTime ( hours , minutes , seconds );
          cout << "hours: " << hours << endl;
          cout << "minutes: " << minutes << endl;
          cout << "seconds: " << seconds << endl;
       return 0 ;
      }

      /******************************* FUNCTION DEFINITION ******************************
       Name : getTime
       Parameters :
        hours a(n) int * ,
        minutes a(n) int * ,
        seconds a(n) int *

       Returns: Void type
       Comments:
       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      void getTime ( int & hours , int & minutes , int & seconds )
      {
          char ch;
         
          cin >> hours;
          cin >> ch;        // get :
          cin >> minutes;
          cin >> ch;        // get :
          cin >> seconds;
       return;
      }

       

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.