Thread: Math Question

  1. #1

    Question Math Question


    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
    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
    if (minutes < 10)
       cout << "0" << minutes;
       cout << minutes;
    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, 12: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
    Replies: 9
    Last Post: 01-16-2003, 07:36 PM