How to make this programme ask for input again if invalid input is entered (in C programming)? [indistinguishable]

https://stackoverflow.com/questions/42464437/how-to-make-this-program-ask-for-input-again-if-invalid-input-is-entered-in-c-p?fbclid=IwAR1BB7wkcELX0D_GkWAOVPe7m3of-gWMo60PztXTV1YqFD6jijQy1oYkR70

Loop Infinite

                                              #include                                                                        <stdio.h>                                                                        #include                                                                        <ctype.h>                                                                        int                                                  chief                        (                        void                        )                                                                        {                                                                        char                                                  ch                        ;                                                                        float                                                  num1                        ,                        num2                        ,                        answer                        ;                                                  printf                        (                        "Enter the functioning of your choice:\n"                        );                                                  printf                        (                        "a. add      s. decrease\northward"                        );                                                  printf                        (                        "g. multiply q. split\n"                        );                                                  printf                        (                        "q. quit\n"                        );                                                                        while                                                                        ((                        ch                                                =                                                  getchar                        ())!=                        'q'                        )                                                                        {                                                  ch                        =                        tolower                        (                        ch                        );                                                                        //Ignore whitespace                                                                        if                                                                        (                        ch                        ==                        '\n'                        )                                                                        proceed                        ;                                                                        else                                                                        {                                                                        switch                        (                        ch                        )                                                                        {                                                                        //Improver part                                                                        case                                                                        'a'                        :                                                                        //First number                                                  printf                        (                        "Enter showtime number: "                        );                                                                        //Check to see if input is a number                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num1                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as 2.5, -1.78E8, or three: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                                        //2d number                                                  printf                        (                        "Enter second number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num2                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as 2.v, -1.78E8, or 3: "                        );                                                  scanf                        (                        "%*due south"                        );                                                                        }                                                                        //Do math for respective functioning                                                  reply                                                =                                                  num1                                                +                                                  num2                        ;                                                                        //Impress out upshot                                                  printf                        (                        "%.3f + %.3f = %.3f\n"                        ,                                                  num1                        ,                        num2                        ,                        answer                        );                                                                        break                        ;                                                                        //Subtraction function                                                                        instance                                                                        's'                        :                                                  printf                        (                        "Enter beginning number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num1                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Delight enter a number, such every bit 2.5, -i.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                  printf                        (                        "Enter 2nd number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num2                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Delight enter a number, such equally 2.five, -one.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                  reply                                                =                                                  num1                                                -                                                  num2                        ;                                                  printf                        (                        "%.3f - %.3f = %.3f\n"                        ,                                                  num1                        ,                        num2                        ,                        answer                        );                                                                        interruption                        ;                                                                        //Multiplication office                                                                        case                                                                        'm'                        :                                                  printf                        (                        "Enter beginning number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num1                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as ii.5, -i.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                  printf                        (                        "Enter second number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num2                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as 2.5, -1.78E8, or 3: "                        );                                                  scanf                        (                        "%*due south"                        );                                                                        }                                                  reply                                                =                                                  num1                                                *                                                  num2                        ;                                                  printf                        (                        "%.3f * %.3f = %.3f\northward"                        ,                                                  num1                        ,                        num2                        ,                        answer                        );                                                                        interruption                        ;                                                                        //Division part                                                                        example                                                                        'd'                        :                                                  printf                        (                        "Enter starting time number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num1                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as two.5, -1.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                  printf                        (                        "Enter second number: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num2                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such equally 2.v, -ane.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                                        //Check for if number is a zilch                                                                        while                                                                        (                        num2                        ==                        0                        )                                                                        {                                                  printf                        (                        "Please enter a non-zero number, such equally 2.5, -1.78E8, or iii: "                        );                                                                        while                                                                        (                        scanf                        (                        "%f"                        ,&                        num2                        )==                        0                        )                                                                        {                                                  printf                        (                        "Invalid input. Please enter a number, such as 2.5, -1.78E8, or 3: "                        );                                                  scanf                        (                        "%*s"                        );                                                                        }                                                                        }                                                  respond                                                =                                                  num1                                                /                                                  num2                        ;                                                  printf                        (                        "%.3f / %.3f = %.3f\n"                        ,                                                  num1                        ,                        num2                        ,                        answer                        );                                                                        break                        ;                                                                        //For if a not-valid performance is entered                                                                        default                        :                                                  printf                        (                        "That is not a valid operation.\north"                        );                                                                        suspension                        ;                                                                        }                                                                        }                                                  printf                        (                        "Enter the functioning of your choice:\n"                        );                                                  printf                        (                        "a. add      s. decrease\n"                        );                                                  printf                        (                        "m. multiply q. divide\north"                        );                                                  printf                        (                        "q. quit\north"                        );                                                                        }                                                  printf                        (                        "Adieu.\n"                        );                                                                        render                                                                        0                        ;}                                          

Pop posts from this blog

Assignment to develop a non-scientific figurer using C Language-81998

Image

Questions are taken from "C: How to Program" by Deitel and Deitel.

https://www.eecs.wsu.edu/~cs150/tutorial/ CptS 150 Plan Design and Development Tutorial Questions are taken from "C: How to Plan" by Deitel and Deitel. Acknowledgements I would like to thank Janet Raynor, Michelle Antolovich and Kael Rowan for their contribution to this tutorial. Without their hard work, this effort would not have been possible. I would also similar to thank the students for testing the tutorial and providing valuable feedback. -- Teck Choo Tan Introduction to C Programming Short Review Bug 2.7 two.ix 2.x 2.xv 3.43 5.50d Programming Trouble ii.twenty TAKE THE QUIZ! Selection Brusk Review Problems three.11 iii.31 iv.24b, 4.24e 4.thirty Programming Problems 3.35 4.28 three.20 iii.23 Accept THE QUIZ! Loops Brusk Review Problems three.x four.5 four.6b Programming Issues iii.17 3.47b iv.10 4.12 4.18 TAKE THE QUIZ! Functions Short Review Problems 5.vii 5.8 5.xiii five.50 Programming Proble