fork download
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3.  
  4. int main(void)
  5. {
  6. int position;
  7. do
  8. {
  9. printf("Enter the number of the cell y....");
  10. scanf("%d", &position);
  11. const bool input_is_valid = (position == -1) || ((position > 0) && (position < 10));
  12. if (input_is_valid)
  13. break;
  14. printf("\nInput invalid, try again\n");
  15. } while(true);
  16.  
  17. printf("Position was %d\n", position);
  18.  
  19. return 0;
  20. }
  21.  
Success #stdin #stdout 0s 9424KB
stdin
0

11
-2
3
stdout
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