Hi!!
I wanna convert a given amount of seconds into hours, minutes and seconds. I wanna use modulus to get the result I'm looking for. I KNOW that's it's easy but I'm stuck. How ever I turn it around I can't get it to work. Example... the time is 7500 sec. When I convert it I either get 1 hour 75 minutes and 0 sec. or I get 1 hour -4500 min and 0 sec.

This is the code I'm using

// Converting secs into minutes and hours, fastest_Time being 
// the incoming amount of seconds
   int out_Sek, out_Min, out_Hour;
   
      out_Sek = fastest_Time % 60;
      out_Min = ??????? // This is the part I'm having problem with
      out_Hour = fastest_Time /3600;
      cout << "Fastest time was:  " << out_Hour << " hours "<< out_Min<< " min. "<< ut_Sek << " sek. ";

If you have inp_Sec as your input of seconds then you can use it as :

//Here you are trying to acquire all those seconds which cannot be converted to minutes ie anything short of sixty seconds
out_Sec = inp_Sec % 60;

//Here you convert it into proper minutes leaving out the extra seconds as it is integer division
inp_Sec = inp_Sec / 60;

//Here you are trying to acquire all those minutes which cannot be converted to hours ie anything short of sixty minutes
out_Min = inp_Sec % 60;

//Here you are trying to acquire all those minutes which can be converted to hours
out_Hours = inp_Sec / 60;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.