In: Computer Science
Time Calculator Create a C++ program that lets the user enter a number of seconds and produces output according to the following criteria:
• 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.
• 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 86,400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86,400, the program should display the number of days in that many seconds.
Please find the C++ code for the following:
Code:
#include <iostream>
using namespace std;
int main()
{
int seconds;
//Prompt the user to enter the number of seconds
cout <<"Enter a number of seconds: ";
cin >> seconds;
//Check if the number of seconds entered by the user is greater
than or equal to 86,400,
if(seconds>=86400)
{
//Then the program should display the number of days in that many
seconds.
cout<<"The Number of days is "<<seconds /
86400.0;
}
//Check if the number of seconds entered by the user is greater
than or equal to 3,600,
else if(seconds>=3600)
{
//Then the program should display the number of hours in that many
seconds.
cout<<"The Number of hours is "<<seconds/3600.0;
}
//Check if the number of seconds entered by the user is greater
than or equal to 60,
else if(seconds>=60)
//the program should display the number of minutes in that many
seconds.
{
cout<<"The Number of minutes is "<<seconds/60.0;
}
//Else case where none of the condition matches
else
{
cout<<"The Number of seconds is "<<seconds;
}
return 0;
}
Please check the
compiled program and its output for your reference:
Output:
Sample case-1:
Sample case-2:
Sample case-3:
(I believe that I made the code simple and understandable. If you still have any query, Feel free to drop me a comment)
Hope this Helps!!!
Please upvote as well, If you got the answer?
If not please comment, I will Help you with that...