lundi 29 avril 2019

Program keeps breaking into infinite loop while trying to input user time using cin with a do while loop in c++

I am trying to write a program for class where we have to take user time (departure + arrival time) and then output whatever the user wrote to the console. I am using a do while loop. I am using an if statement to validate property entry. When I run the program, every single fucking time, it just keeps asking for arrival time over and over again. I need to append "am" or "pm" depending on what the user entered, which is why that char array of two values is there. PLEASE help

char ampm1[2];

    // char ampm = 'p';
    int temp;
    do 
    {
        cout << "Please enter your arrival time in the following format: '10:30'. This IS NOT MILITARY TIME.";
        cin >> temp;
        arrival_hour = temp / 100;
        arrival_min = temp % 100;
        cout << "Is this AM or PM?";
        cin >> ampm1;
    } 
    while (arrival_hour > 12 || arrival_hour < 0 || departure_min >= 60);




    cout << "Your arrival time is: " << setfill('0') << setw(2) << arrival_hour << ":" << setfill('0') << setw(2)
        << arrival_min << ampm1;

Aucun commentaire:

Enregistrer un commentaire