C: Do-While Loop Repeating Too Much!

前端 未结 3 1449
醉梦人生
醉梦人生 2021-01-27 17:05

I have a small program that which is confusing me. I am trying using a loop to take input from user. In case input is wrong, it is repeated again but if it is right, it exits.

3条回答
  •  无人及你
    2021-01-27 18:08

    You want

    do
    {
    
    } while (condition);
    

    As your forgot the semicolon, you get:

    do
    {
        ....
    }
    
    while(condition)
        do something else;
    

    You could have noticed that just by auto-indenting your code in an editor like I did on your question.

    Also when you do some scanf you should rather include the \n in the format specification.

提交回复
热议问题