Error check results in an infinite loop

Hi all,

I made a small program to test out taking an input of a time in HHMMSSMMM (hours minutes second milliseconds) format, then displaying the hours, minutes, seconds, and milliseconds separately. I tried to make an error check to reject the input if it was longer than 9 digits, but the program gets stuck in an infinite loop with the code I currently have. I have no idea why this infinite loop is happening, any help would be appreciated!

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
33
34
35
36
37
38
#include <iostream>
#include <string>

using namespace std;


int main()
{

    int test;
    int hours;
    int minutes;
    int seconds;
    int milliseconds;


    do{
    cin >> test;
    cin.ignore();

    milliseconds = test % 1000;
    seconds = (test / 1000) % 100;
    minutes = (test / 100000) % 100;
    hours = test / 10000000;

    if(seconds > 59 || minutes > 59 || hours > 23)
        cout << "ERROR" << endl;
    else{
    cout << "milliseconds: " << milliseconds << endl;
    cout << "seconds: " << seconds << endl;
    cout << "minutes: " << minutes << endl;
    cout << "hours: " << hours << endl;
    }
    
    }while(seconds > 59 || minutes > 59 || hours > 23);
    
    return 0;
}
Topic archived. No new replies allowed.