[try Beta version]
Not logged in

 
Please Help Fix My Program

Sep 22, 2015 at 9:45pm
Hello, I am very new to the world of coding and I am trying to write a program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds (if the time is 9630 seconds, the output should be 20:30:40
This is what I have right now and it doesn't work at all:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include <iostream>

using namespace std;

int main()
{
    int hours;
    int minutes;
    int seconds;
    int time = 0;
    cout << "Please enter elapsed time in seconds: ";
    cin >> time;
    cout << endl;
    hours = time / 3600;
    time = time - hours * 3600;
    minutes = time / 60;
    time = time - minutes * 60;
    seconds = time;
    cout << hours;
    if (minutes < 10)
        cout << ":0" << minutes;
    else
        cout << ":" << minutes;
    if (seconds < 10)
        cout << ":0" << seconds;
    else
        cout << ":" << seconds;
    cout << endl;
    return 0;
}
}
Sep 22, 2015 at 9:49pm
Hmmm, remove last } and try.
Topic archived. No new replies allowed.