showTime()?

This is a discussion on showTime()? within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> #include<conio.h> using std::cout; using std::cin; using std::endl; // function prototype void showTimeH( int ); void showTimeM( int ); ...

  1. #1
    o0o
    o0o is offline
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37

    showTime()?

    Code:
    #include<iostream>
    #include<conio.h>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    // function prototype
    
    void showTimeH( int );
    void showTimeM( int );
    
    int main()
    {
        // declare variable
        
        int hours, minutes, seconds;
        
        // read time in format h/m/s
        
        cout<< "What is the time now:(h/m/s)";
        cin>> hours >> minutes >> seconds;
        
        // show time in seconds
        // call functions showTimeH() % showTimeM()
        
        cout<< "Hours        " << "Minutes          " << "Seconds" <<endl;
        cout<< showTimeH( hours ) << "-" << showTimeM( minutes ) << "-"<< seconds;
        
    getch();
    }
    
    // function definition
    
    void showTimeH( int hValue )
    {
        cout<< hValue*60; 
    }
    
    void showTimeM( int mValue )
    {
        cout<< mValue*60;
    }
    The functions showTimeH( hours )
    &
    showTimeM( minutes )

    donot work? They should give hours*60 = ........ seconds and minutes*60=........seconds?
    respectively

    ?

  2. #2
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    because showTimeH and showTimeM aren't supposed to output anything, they should return a value, something like this:
    Code:
    int showTimeH(int hValue) {
        return 60 * hValue;
    }
    int main(void) {
        int hours;
        cin >> hours;
        cout << showTimeH(hours);
    }
    Another note, I guess that multiplying hValue by 60 gives the number of minutes, and I guess this isn't what you want it to do, so could you please explain more what are you actually trying to do?

  3. #3
    o0o
    o0o is offline
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37
    Yes it works and sorry i missed another *60 in hours to convert it into secds/ thanku

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error check...loop
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-01-2001, 09:46 PM

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