Write a program which asks the user to either convert the number of days into hours or minutes. Based on the option entered by user your program should calculate the result accordingly.

4 Years
Discussion Span
Last Post by talha ijaz

And your question is what? Sorry, but we don't do your homework for you. Just FYI:

  1. There are 24 hours in a day.
  2. There are 60 minutes in an hour.
  3. There are 60 seconds in a minute.

You get to do the math! :-)


You get to do the math! :-)

For massive bonus points, incorporate chronological adjustments in your math (eg. leap years, leap seconds). Date and time calculations are shockingly complex when you look for higher correctness across the board. Most libraries even put a lower bound on supported dates to avoid changes in the standard calendar.

Even given its relatively limited scope I found that time.h was the second or third most time consuming part of the standard library to implement correctly.


Also, time.h is only accurate since 1970 (I think that's the beginning date). So if you wanted to calculate how many minutes I've been alive you wouldn't be able to do it with any of the functions in time.h. AFAIK the only way to do that is to use boost time/date c++ class or write your own class.

Edited by Ancient Dragon


try this

#include <iostream>
using namespace std;
int main () {

int a;
char b;
cout<<"Enter the number of days you want to convert:-   "<<endl;
cout<<"\nWould you like to convert it in (h)ours or (m)inutes?"<<endl;
if (b='h')  {
   cout<<"\nHours =  "<<a*24;
else if (b='m') {
   cout<<"\nMinutes =  "<<a*24*60;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.