I am creating a program that will convert seconds into hrs mins and the remainding seconds. I've got the hours part down but for minutes im trying to use the remainder funtion.

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
int secns, mins, hrs, convs, sec, sph, s;
cout<<"Enter the number of conversions you would like performed\n";
for (int num=1; num<=convs; num++)
    cout<<"Enter the number of seconds for the conversion #"<<num<<"\n";
return 0;

the remainder output should be 11 but im getting 703??????
anyone that can tell me whats wrong and i am aware that the code for the program is not finished.

Minutes is calculated like this (I think). You have to subtract from original value of secs the number of seconds in hrs variable then mod the result with 60 (60 seconds in one minute).

secs -= (hours * sph);
minutes = secs % 60;

Now the remaining seconds is

secs -= minutes * 60;

In line 11 do you mean to be creating a value for number of seconds in a minute, like your sph value for hours? Then you ought to have something like:

mph = 60;

And not use the <= that you wrote, which makes a statement that does nothing useful.

Then, your conversion becomes a series of divides and modulus operations.

hrs = sec / sph;
sec = sec % sph;
mins = sec / mph;
sec = sec % mph;

You're done. sec now holds the remaining seconds.


This article has been dead for over six months. Start a new discussion instead.