Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that asks the user to enter the time in seconds, and will displa

ID: 3640797 • Letter: W

Question

Write a program that asks the user to enter the time in seconds, and will display the time entered in hour-minute-second format(30 points):
- There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to 3,600, the program should display the number of hours in that many seconds.
- There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds.
Hint: you should use three variables of type int to store the number of hours, minutes and seconds.
The following is an example of a program output:
Enter the time in seconds: 700
The time is 0 hours, 11 minutes, and 40 seconds.
-----------------------------------------------
Enter the time in seconds: 25000
The time is 6 hours, 56 minutes, and 40 seconds.

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
   //PROTOTYPES
   void printHourMinuteSecond(int secs);

   //LOCAL DECLARATIONS
   int secs;

   //PROCEDURES
   while (true)
   {
      cout << "Enter the time in seconds: ";
      cin >> secs;
      printHourMinuteSecond(secs);
      cout << "----------------------------------------------- ";
      if (secs < 0) break; //enter negative seconds to end program
   }

   cout << endl;
   return 0;
}

//---------------------------------------------------------
// FUNCTION DEFINITIONS
//---------------------------------------------------------
void printHourMinuteSecond(int secs)
{
   if (secs >= 0)
   {
      int ss = secs % 60;
      int mm = secs / 60 % 60;
      int hh = secs / 3600;
      cout << "The time is " << hh << " hours, "
           << mm << " minutes, and "
           << ss << " seconds. ";
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote