GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Feb-2008, 23:20
markc++ markc++ is offline
New Member
 
Join Date: Feb 2008
Posts: 8
markc++ is an unknown quantity at this point

Seconds to Hours:Minutes:Seconds C++


Write a c++ program that process input time in seconds. The program then output time in hours:minutes:seconds?
Please use integer division and the modulus operator.
  #2  
Old 05-Feb-2008, 06:20
davis
 
Posts: n/a

Re: Seconds to Hours:Minutes:Seconds c++


I just love the "non-question" question...couldn't read the guidelines, huh?

CPP / C++ / C Code:
#include <iostream>
#include <string>

using namespace std;

void print_with_formatting( const unsigned int value )
{
    if( value == 0 )
    {
	cout << "00";
    }
    else if( value < 10 )
    {
	cout << "0" << value;
    }
    else
    {
	cout << value;
    }
}

int main()
{
    const static unsigned int SECONDS_IN_AN_HOUR    =	3600;
    const static unsigned int SECONDS_IN_A_MINUTE   =	60;

    cout << "Enter time value in seconds: ";
    unsigned int ui_tv;
    cin >> ui_tv;

    if( ui_tv > 0 )
    {
	print_with_formatting( (unsigned int)(ui_tv / SECONDS_IN_AN_HOUR) );
	cout << ":";
	print_with_formatting( (unsigned int)((ui_tv % SECONDS_IN_AN_HOUR) / SECONDS_IN_A_MINUTE) );
	cout << ":";
	print_with_formatting( (unsigned int)((ui_tv % SECONDS_IN_AN_HOUR) % (SECONDS_IN_A_MINUTE)) );
    }
    else
    {
	cout << "00:00:00";
    }
    cout << endl;

    return 0;
}

Output:

Code:
Enter time value in seconds: 0 00:00:00 Enter time value in seconds: 1 00:00:01 Enter time value in seconds: 61 00:01:01 Enter time value in seconds: 3661 01:01:01 Enter time value in seconds: 9000 02:30:00 Enter time value in seconds: 6703 01:51:43


:davis:
  #3  
Old 11-Feb-2008, 23:38
markc++ markc++ is offline
New Member
 
Join Date: Feb 2008
Posts: 8
markc++ is an unknown quantity at this point

Re: Seconds to Hours:Minutes:Seconds c++


Thank you so much. I am a beginner . would u give link for me to study c++ more easily( Please ,I do not want subscriptions)
Again I really appreciated.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
constructors/classes mapes479 C++ Forum 3 19-Nov-2006 18:34
gettimeofday() scorpio2002 C Programming Language 1 01-Nov-2006 13:55
Simple countdown from 2 minutes miniwolle Python Forum 4 15-Apr-2006 14:28
Time, no seconds YayItsDan MySQL / PHP Forum 0 28-Jun-2005 20:45
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 16:13

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.