September 8th, 2013, 10:05 AM
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;
September 8th, 2013, 02:50 PM
What happens if you type in a negative number (say -1234)
What happens if you type in a very large number (say 123456789012345678901234567890)
What happens if you type in a string (say hello)
If you're not at the stage of advanced error checking, then does it seem to work for some small positive numbers that you know should produce a specific answer (say 600).
Also, when you post code, please use the [code][/code] tags around the code to preserve the formatting.