For my program when the output is displayed it comes out in hours. I want to remove it so hours does not come up. How do i do this?
I don't have any input containing "hours" on my code. Before the decimal point of the time displayed. It only shows one zero. Whereas i need 2 zero's for hours, two for minutes, two for seconds. etc how do i also get that up?
It would really help if you showed the code that you currently have (along with an example of the current output)... Assuming you're using something like the date function, you just need to use the correct format parameters that support leading zeros.
#include <string> float a, b, c, d, e, f; cout << "Enter the respective speeds in km/h for swimming, cycling, and running: " << endl; // Enter output for speeds cin >> a;// initializing the float / showing speed of swimming cin >> b;// initializing the float / showing speed of cycling cin >> c;// initializing the float / showing speed of running cout << "Enter the respective distances in km for swimming, cycling, and running: " << endl;// Enter the output for distances cin >> d;// initializing the float / showing distance of swimming cin >> e;// initializing the float / showing distance of cycling cin >> f;// initializing the float / showing distance of running cout << "Swimming time:" << (d*60)/a << endl;// Swimming distance being divided by swimming speed to come up with total time of swimming cout << "Cycling time:" << (e*60)/b << endl;// Cycling Distance being divided by cycling speed to come up with total time of cycling cout << "Running time:" << (f*60)/c << endl;// Running distance being divided being divided with running speed to work out total time of running cout << "Total time:" << (d/a)+(e/b)+(f/c)* 60 << endl;// Total Time of the triathlon including all the swimming, cycling and running system("pause") ; return 0; } the thing is. its posting times and distances. There off. Can anyone find the problem with the code i have created. Theres no errors. just the times are off and i need the time format to not be in hours but like i posted above.
Oh. C++ Instead of just cout'ing your integers, you need to use printf. http://www.cplusplus.com/reference/clibrary/cstdio/printf.html is a 'help' file for it. To print a zero padded integer that is to be at least 2 integers wide, I believe you need to do something like: printf( "%02d", theInt ); Hopefully that makes sense...