Wrox Programmer Forums Convert time in seconds to hh:mm:ss
 |
 C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
March 18th, 2008, 04:43 AM
 41509331 Registered User Join Date: Mar 2008 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts
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?

 Similar Threads Thread Thread Starter Forum Replies Last Post Convert seconds to HH:MM:SS bph SQL Server 2000 11 July 31st, 2009 01:53 PM converting HH:MM to HH.MM nasirmunir PHP How-To 5 July 11th, 2008 01:33 PM Converting number to hh:mm dlyles Beginning VB 6 8 September 19th, 2006 12:27 PM Convert Seconds to HH:MM:SS jpillonel Crystal Reports 0 December 17th, 2003 09:20 AM validation of [HH]:mm beastwood_uk Excel VBA 3 August 10th, 2003 08:37 AM