0

I've figured it out but I want to know HOW.

When I do code I try and figure out the math behind it on the side so I know exactly what is going on.

But this time has stumped me. I know what the code is suppose to be, so it has been implemented but understanding HOW it works is driving me bonkers! If anyone can help explain it would be wonderful.

```
// calculate seconds to days/hours/minutes/seconds
#include <iostream>
using namespace std;
const int HOURS_IN_DAY = 24; // it's good form to make
const int MINUTES_IN_HOUR = 60; // symbolic constants all caps
const int SECONDS_IN_MINUTE = 60;
int main()
{
long InSeconds, InMinutes, InHours;
int seconds;
int minutes;
int hours;
int days;
cout << "This program will turn your seconds into days, hours, minutes and seconds." << endl;
cout << "Enter the amount of seconds:__________\b\b\b\b\b\b\b\b\b\b";
cin >> InSeconds; // I typically input 31600000 for reference
// compute in reverse
// THIS IS WHERE THE PROBLEMS START
// compute seconds
// I see this as 31600000 % 60 = 526666.666666 and the output it gives is 40 seconds.
// Yes the % gives you the remainder / number after decimal... I don't see where the 40 comes from?
seconds = InSeconds % SECONDS_IN_MINUTE ;
// throw away seconds used in previous statement and convert to minutes
// which seconds are thrown away?... and so on throughout this simple program
InMinutes = InSeconds / SECONDS_IN_MINUTE ;
// compute minutes
minutes = InMinutes % MINUTES_IN_HOUR ;
// throw away minutes used in previous statement and convert to hours
InHours = InMinutes / MINUTES_IN_HOUR ;
// compute hours
hours = InHours % HOURS_IN_DAY ;
// throw away hours used in previous statement and convert to days
days = InHours / HOURS_IN_DAY ;
cout << "That's " ;
if (days > 0)
cout << days << " days " ;
if (hours > 0)
cout << hours << " hours " ;
if (minutes > 0)
cout << minutes << " minutes " ;
if (seconds >0)
cout << seconds << " seconds " ;
cout << endl ;
cin.get();
cin.get();
return 0;
}
```

*Edited 4 Years Ago by antoinette.boulevard*