Hi guys, I am a beginner c++ programmer. I was solvig the following question:
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// seconds.cpp -- converts seconds to days, hours and minutes
#include <iostream>
using namespace std;
int main()
{
long seconds;
cout << "Enter the number of seconds: ";
cin >> seconds;
unsigned long days = seconds / 86400;
unsigned long hours = seconds % days;
unsigned long minutes = seconds % hours;
unsigned long rem_seconds = seconds % minutes;
cout << seconds << " seconds = " << days << " days, "
<< hours << " hours, " << minutes << " minutes, "
<< rem_seconds << " seconds." << endl;
return 0;
}
|
Unfortunately, when I enter the number of seconds (31600000), I get the following error:
Floating point exception (core dumped).
But, it works fine with smaller inpute (like 3160000). Can anyone please tell me what is going on here. (I use gcc 4.6.3)