#include <stdio.h>#include <stdbool.h> int main(void) { int position; do { printf("Enter the number of the cell y...."); scanf("%d", &position); const bool input_is_valid = (position == -1) || ((position > 0) && (position < 10)); if (input_is_valid) break; printf("\nInput invalid, try again\n"); } while(true); printf("Position was %d\n", position); return 0;}
0 11 -2 3
Enter the number of the cell y.... Input invalid, try again Enter the number of the cell y.... Input invalid, try again Enter the number of the cell y.... Input invalid, try again Enter the number of the cell y....Position was 3
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!