Guest User

Untitled

a guest
Oct 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int myInt = 6;
  7.     int otherInt = 12;
  8.     int userInt;
  9.     int Y = Y;
  10.     int N = N,n;
  11.    
  12. go1: printf ( "Please put in the number '6' or the number '12': " );
  13.    
  14.     scanf ( "%d",&userInt );getchar();
  15.    
  16.     if ( userInt == myInt )
  17.         {
  18.             printf ( "You entered: 6!\n" );
  19.             go2: printf ( "Would you like to start again? Y/N\n\n" );
  20.             scanf ( "%s",&userInt );getchar(); /*It's important not to use '%d' here because '%d' means decimal number (but here we need a letter!)*/
  21.             if ( userInt == 'Y' )
  22.                 {
  23.                     goto go1;
  24.                 }
  25.             else if ( userInt == 'y' )
  26.                 {
  27.                     goto go1;
  28.                 }
  29.             else if( userInt == 'N')
  30.                 {
  31.                     exit(0);  //If either 'Y' or 'N' is enter, the program exits with 0
  32.                 }
  33.             else if( userInt == 'n')
  34.                 {
  35.                     exit(0);  //If either 'Y' or 'N' is enter, the program exits with 0
  36.                 }
  37.             else
  38.                 {
  39.                 printf ("Invalid answer.\n");
  40.                 goto go2; //Go back to question above
  41.                 }      
  42.         }
  43.     if ( userInt == otherInt )
  44.         {
  45.             printf ( "You entered: 12!\n" );
  46.             printf ( "Would you like to start again? Y/N\n\n" );
  47.             scanf ( "%s",&userInt );  /*It's important not to use '%d' here because '%d' means decimal number (but here we need a letter!)*/
  48.             if ( userInt == 'Y' )
  49.                 {
  50.                     goto go1;
  51.                 }
  52.             else if ( userInt == 'y' )
  53.                 {
  54.                     goto go1;
  55.                 }
  56.             else if( userInt == 'N')
  57.                 {
  58.                     exit(0);  //If either 'Y' or 'N' is enter, the program exits with 0
  59.                 }
  60.             else if( userInt == 'n')
  61.                 {
  62.                     exit(0);  //If either 'Y' or 'N' is enter, the program exits with 0
  63.                 }
  64.             else
  65.                 {
  66.                 printf ("Invalid answer.\n");
  67.                 goto go2; //Go back to question above
  68.                 }      
  69.         }
  70.     else
  71.         {
  72.             printf(  "Can't you read? Try again!\n" );
  73.             getchar();
  74.             goto go1;
  75.         }
  76.     return 1;
  77. }
Add Comment
Please, Sign In to add comment