Advertisement
dmilicev

enter_number_in_max_5_attempts.c

Dec 19th, 2019
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None
  1. /*
  2.  
  3.     enter_number_in_max_5_attempts.c
  4.  
  5.  
  6.     Program that will stop the user from inputting a number between 1 and 3
  7.  
  8.     after 5 invalid inputs.
  9.  
  10.  
  11.     You can find all my C programs at Dragan Milicev's pastebin:
  12.  
  13.     https://pastebin.com/u/dmilicev
  14.  
  15.     https://www.facebook.com/dmilicev
  16.  
  17. */
  18.  
  19. #include <stdio.h>
  20.  
  21. int main(void)
  22. {
  23.     int number, good=0, counter=0;
  24.  
  25.     do {                                // do-while loop must be executed at least one time
  26.  
  27.         counter++;                      // count attempts
  28.  
  29.         printf("\n\n %d. attempt. Enter a number between 1 and 3, number = ", counter );
  30.         scanf("%d",&number);
  31.  
  32.         if ( number>=1 && number<=3 )   // condition for good input
  33.             good=1;
  34.  
  35.     } while( !good && counter<5 );
  36.  
  37.     if ( counter == 5 )
  38.         printf("\n\n \t You have used all 5 allowed attempts to enter a number. \n\n" );
  39.     else
  40.         printf("\n\n \t In %d. attempt entered number is %d \n\n", counter, number );
  41.  
  42.  
  43.     return 0;
  44.  
  45. } // main()
Advertisement
RAW Paste Data Copied
Advertisement