232k views
0 votes
Write a program that asks the user to enter a number of 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. Programming Challenges 185 The Time Calculator Problem VideoNote 186 Chapter 3 Decision Structures • 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.

1 Answer

5 votes

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable to store seconds

long long int sec;

cout<<"enter seconds:";

// read the seconds

cin>>sec;

// if seconds is in between 60 and 3600

if(sec>=60&& sec<3600)

{

// find the minutes

int min=sec/60;

cout<<"there are "<<min<<" minutes in "<<sec<<" seconds."<<endl;

}

// if seconds is in between 3600 and 86400

else if(sec>=3600&&sec<86400)

{

// find the hours

int hours=sec/3600;

cout<<"there are "<<hours<<" hours in "<<sec<<" seconds."<<endl;

}

// if seconds is greater than 86400

else if(sec>86400)

{

// find the days

int days=sec/86400;

cout<<"there are "<<days<<" days in "<<sec<<" seconds."<<endl;

}

return 0;

}

Step-by-step explanation:

Read the seconds from user.If the seconds is in between 60 and 3600 then find the minutes by dividing seconds with 60 and print it.If seconds if in between 3600 and 86400 then find the hours by dividing second with 3600 and print it. If the seconds is greater than 86400 then find the days by dividing it with 86400 and print it.

Output:

enter seconds:65

there are 1 minutes in 65 seconds.

enter seconds:3700

there are 1 hours in 3700 seconds.

enter seconds:900000

there are 10 days in 900000 seconds.

User Jeff Puckett
by
5.4k points