How to change time format!!!

Discussion in 'Programming' started by chum112, Mar 11, 2007.

  1. #1
    For my program when the output is displayed it comes out in hours. I want to remove it so hours does not come up. How do i do this?
     
    chum112, Mar 11, 2007 IP
  2. chum112

    chum112 Guest

    Messages:
    1,131
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't have any input containing "hours" on my code. Before the decimal point of the time displayed. It only shows one zero. Whereas i need 2 zero's for hours, two for minutes, two for seconds. etc how do i also get that up?
     
    chum112, Mar 11, 2007 IP
  3. chum112

    chum112 Guest

    Messages:
    1,131
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I mean like this 00:08:03.9 . How do i get that time format ?
     
    chum112, Mar 11, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It would really help if you showed the code that you currently have (along with an example of the current output)...

    Assuming you're using something like the date function, you just need to use the correct format parameters that support leading zeros.
     
    TwistMyArm, Mar 11, 2007 IP
  5. chum112

    chum112 Guest

    Messages:
    1,131
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    #include <string>
    float a, b, c, d, e, f;
    cout << "Enter the respective speeds in km/h for swimming, cycling, and running: " << endl; // Enter output for speeds
    cin >> a;// initializing the float / showing speed of swimming
    cin >> b;// initializing the float / showing speed of cycling
    cin >> c;// initializing the float / showing speed of running
    cout << "Enter the respective distances in km for swimming, cycling, and running: " << endl;// Enter the output for distances
    cin >> d;// initializing the float / showing distance of swimming
    cin >> e;// initializing the float / showing distance of cycling
    cin >> f;// initializing the float / showing distance of running
    cout << "Swimming time:" << (d*60)/a << endl;// Swimming distance being divided by swimming speed to come up with total time of swimming
    cout << "Cycling time:" << (e*60)/b << endl;// Cycling Distance being divided by cycling speed to come up with total time of cycling
    cout << "Running time:" << (f*60)/c << endl;// Running distance being divided being divided with running speed to work out total time of running
    cout << "Total time:" << (d/a)+(e/b)+(f/c)* 60 << endl;// Total Time of the triathlon including all the swimming, cycling and running
    system("pause") ;
    return 0;
    }


    the thing is. its posting times and distances. There off. Can anyone find the problem with the code i have created. Theres no errors. just the times are off and i need the time format to not be in hours but like i posted above.
     
    chum112, Mar 12, 2007 IP
  6. chum112

    chum112 Guest

    Messages:
    1,131
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    lol changing this time format is like mission impossible with c++ lol.
     
    chum112, Mar 12, 2007 IP
  7. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Oh. C++ :)

    Instead of just cout'ing your integers, you need to use printf. http://www.cplusplus.com/reference/clibrary/cstdio/printf.html is a 'help' file for it.

    To print a zero padded integer that is to be at least 2 integers wide, I believe you need to do something like:
    printf( "%02d", theInt );

    Hopefully that makes sense...
     
    TwistMyArm, Mar 12, 2007 IP