time

Here's the problem I need help on.

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.
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    double seconds;
    double minutes = 60.0;
    double hours = 3600;
    double days = 86400;

    cout << "Enter a number of seconds: " << endl;
    cin >> seconds;



    cout << fixed << showpoint << setprecision(1);
    if (minutes >=60)
    { cout << "There are minutes in seconds." << setw(1) << minutes << endl;}
    cout << fixed << showpoint << setprecision(1);
    if (hours >=3600)
    { cout << "There are hours in seconds." << setw(1) << hours << endl;}
    cout << fixed << showpoint << setprecision(1);
    if (days >=86400)
    { cout << "There are days in seconds." << setw(1) << days << endl;}

cout << endl;
     return 0;
}


also i was wondering how do i include these in the code?
There are 1666.667 minutes in 100000.000 seconds.
There are 27.778 hours in 100000.000 seconds.
There are 1.157 days in 100000.000 seconds.
I suggest you look into <ctime>. They're functions in that library that will be able to help time your program.

http://www.cplusplus.com/reference/clibrary/ctime/
You will need to put the conversions into your program as well.
any example? ty
1
2
3
4
5
6
//as long as there are more than 60 seconds
while (seconds > 60)
{
   seconds -= 60; // subtracts 60 seconds from the number of seconds
   ++minutes;      // adds 1 to the number of minutes
}
Topic archived. No new replies allowed.