#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Can you prove my program isn't 100% accurate?


    Hi everyone.
    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:

    #include <iostream>
    using namespace std;
    int main()
    {
    // 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;
    return 0;
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,364
    Rep Power
    1870
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo