September 8th, 2013, 11:05 AM
Join Date: Sep 2013
Time spent in forums: 1 h 2 m 31 sec
Reputation Power: 0
Can you prove my program isn't 100% accurate?
I've just started with C++, and everything's going well so far. The book I'm using has some generally good examples/exercises. I was hoping someone could proof-check this simple program for me though. Not asking anyone to do my homework, the program compiles and functions correctly (I believe). I just wanted some professional advice/opinions.
I'm supposed to request input from a user for the amount of time in seconds for any event to occur. here's what I've come up with:
using namespace std;
// Declare variables.
int total, hours, seconds, minutes;
// Prompt user for input.
cout << "Enter time in seconds:" << endl;
cin >> total;
// Identify variables.
hours = total / 3600;
hours = hours % 3600;
minutes = total / 60;
minutes = minutes % 60;
seconds = total % 60;
// Output conversion, including colons as separators.
cout << hours << ":" << minutes << ":" << seconds << endl;