Here's the excercise from a C++ book:
Write a program that asks the user to enter the number of seconds as an integer value(use type long) and that then displays the equivalent time in days, hours, minutes, and
seconds. Use symbolic constants to represent the number of hours in the day, the number of minutes in an hour, and the number of seconds in a minute. The output should
look like this:
Enter the number of seconds: 31600000
31600000 seconds = 365 days, 46 minutes, 40 seconds
This is not a homework of any kind, I self-teach myself C++ for fun.
Here's what I've done so far:
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
|
#include <iostream>
const int HRS_PER_DAY = 24;
const int MIN_PER_HR = 60;
const int SEC_PER_MIN = 60;
int main()
{
using namespace std;
long int seconds;
int days, minutes;
cout << "Enter the number of seconds: ";
cin >> seconds;
days = seconds / SEC_PER_MIN / MIN_PER_HR / HRS_PER_DAY;
hours = //stuck
minutes = //stuck
seconds = //stuck
cout << seconds << " seconds = " << days << " days, " << minutes << " minutes, " << seconds << " seconds";
cin.get();
cin.get();
return 0;
}
|
Basically I'm stuck at the part where I have to come up with a formula that will give the result of seconds in days, hours, minutes and seconds not as separate values but as a single value meaning that 31600000 seconds is equivalent to 365 days, 46 minutes and 40 seconds.
*I assume I should use the % operator, but I might be wrong at the same time.
Thanks.