Math Question

This is a discussion on Math Question within the C++ Programming forums, part of the General Programming Boards category; Hello, I need to know how to make my program display 3:04 instead of 3:4 when you enter 184 as ...

  1. #1
    DarkEldar77
    Guest

    Question Math Question

    Hello,

    I need to know how to make my program display 3:04 instead of 3:4 when you enter 184 as your minutes?

    Thank You For Your Help.


    /*Source Code*/

    #include <iostream.h>

    int main(){

    int enterminutes;
    double minutes;
    double hours;

    cout <<"Enter the number of minutes: "<<endl;
    cin >> enterminutes;

    hour = enterminutes/60;
    minutes = (enterminutes %60);

    cout <<"The time is: "<<hour<<":"<<minutes<endl;

    return (0);
    }

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    a combination of several output format specifiers using printf() or cout should do the trick. Otherwise you could use an if statement checking if minutes is less than 10. If so print a zero before printing the minutes, else just print the minutes.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Code:
    if (minutes < 10)
       cout << "0" << minutes;
    else
       cout << minutes;
    Alternatively:
    Code:
    cout << (minutes < 0 ? "0" : "") << minutes;
    You might want to also check that minutes is between 0 and 59, and add some type of error handling code if not.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 01:14 PM
  2. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. More a math question than an algorithm
    By Gustaff in forum C Programming
    Replies: 1
    Last Post: 01-28-2003, 01:10 PM
  5. Stupid Math Question....really stupid
    By ToLazytoSignIn in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-16-2003, 07:36 PM

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