View Single Post
  #1 (permalink)  
Old March 18th, 2008, 04:43 AM
41509331 41509331 is offline
Registered User
 
Join Date: Mar 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert time in seconds to hh:mm:ss

Hey can i get some help on how to convert time from seconds to HH:SS:MM please?

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{
   string name;
   float weight;
   int calories;
   int steps_flight;
   int time_required;
   double CPerSteps;
   double stepsClimb;
   double flightStairs;
   double howLong;
   double hour;
   double min;
   double sec;


   cout << "Enter your name: ";
   cin >> name;

   cout << "Enter your weight: ";
   cin >> weight;

   cout << "Enter the number of calories you wish to burn: ";
   cin >> calories;

   cout << "Enter the number of steps per flight of stairs: ";
   cin >> steps_flight;

   cout << "Enter the time in second to climb one flight of stairs: ";
   cin >> time_required;

      cout << name << " burns " << fixed << setprecision(2) << CPerSteps << " calorie per step" << endl;


      stepsClimb = calories / (0.0125 * weight);

      flightStairs = stepsClimb / steps_flight;

      cout << name << " needs to climb " << fixed << setprecision(0) << stepsClimb << " steps " << "(" << fixed << setprecision(0) << flightStairs << " flight of stairs)" << " to burn " << calories << " calories" << endl;


      howLong = stepsClimb * (time_required / steps_flight);


   hour = howLong / 3600;
   howLong = howLong % 3600;
   min = howLong / 60;
   howLong = howLong % 60;
   sec = howLong;


      cout << "This will take " << hour << ":" << min << ":" << sec << endl;

   system("pause");
   return 0;
}




thats what my program looks like but i keep getting an error
 howLong = howLong % 3600;



is there another way to formulate this? so that the time can be converted rightly?
Reply With Quote