C++ Program to Convert Hours to Minutes and Seconds

«
»

This is a C++ Program to Convert Hours in Terms of Minutes and Seconds.

Problem Description

The program converts hours into minutes and seconds.

Problem Solution

1. The program takes number of hours and stores it.
2. Hours are converted into minutes by multiplying with 60.
3. Seconds are calculated by multiplying minutes with 60.
4. The result is printed.
5. Exit.

C++ Program/Source code

Here is the source code of C++ Program to Convert Hours in Terms of Minutes and Seconds. The program output is shown below.

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.     float hrs, min, sec = 0;
  6.     cout << "Enter hours : ";
  7.     cin >> hrs;
  8.     min = hrs * 60;
  9.     sec = min * 60;
  10.     cout << "\n" << hrs << " hours = " << min << " minutes = " << sec << " seconds";
  11.     return 0;
  12. }
Program Explanation

1. The user is asked to enter the number of hours and it is stored in the float variable ‘hrs’.
2. Minutes are calculated by multiplying ‘hrs’ with 60 and the value is stored in ‘min’.
3. ‘min’ is multiplied by 60 and stored in the variable ‘sec’ which gives seconds.
4. Hours in terms of minutes and seconds is then printed.

Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement
Runtime Test Cases
Case 1 :
Enter hours : 6
6 hours = 360 minutes = 21600 seconds
 
Case 2 :
Enter hours : 1.5
1.5 hours = 90 minutes = 5400 seconds
 
Case 3 :
Enter hours : 24
24 hours = 1440 minutes = 86400 seconds

Sanfoundry Global Education & Learning Series – C++ Programs.

To practice all C++ programs, here is complete set of 1000+ C++ Programming examples.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.