What am I doing wrong?

This code works for some figures but not others. Like when i input "900" seconds, I get an error message that reads: "floating point exception (core dumped)" but it'll take 901 seconds with no issues...

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
  #include <iostream>
#include <iomanip>  //u

using namespace std;
int main()
    {

    int s, m, h, seconds;

    cout<<"Enter a number of seconds between 0 to 86,400 to convert: "<<endl;
    cin>>seconds;
    cout<<endl;

    if(seconds >= 0){
        h = seconds / 3600;
        seconds = seconds % 3600;
        m = seconds / 60;
        seconds = seconds % 60;
        s = seconds % 60;
        seconds = seconds % seconds;

    }
    else{
        seconds = 0;
    }
    return 0;
    }
Last edited on
what do you mean by
seconds = seconds % seconds;

you can't just divide or mod a value by 0
...
Last edited on
Got it!
I took it out:seconds = seconds % seconds;
and now it works properly for all input figures.
Topic archived. No new replies allowed.