Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int myInt = 6;
- int otherInt = 12;
- int userInt;
- int Y = Y;
- int N = N,n;
- go1: printf ( "Please put in the number '6' or the number '12': " );
- scanf ( "%d",&userInt );getchar();
- if ( userInt == myInt )
- {
- printf ( "You entered: 6!\n" );
- go2: printf ( "Would you like to start again? Y/N\n\n" );
- scanf ( "%s",&userInt );getchar(); /*It's important not to use '%d' here because '%d' means decimal number (but here we need a letter!)*/
- if ( userInt == 'Y' )
- {
- goto go1;
- }
- else if ( userInt == 'y' )
- {
- goto go1;
- }
- else if( userInt == 'N')
- {
- exit(0); //If either 'Y' or 'N' is enter, the program exits with 0
- }
- else if( userInt == 'n')
- {
- exit(0); //If either 'Y' or 'N' is enter, the program exits with 0
- }
- else
- {
- printf ("Invalid answer.\n");
- goto go2; //Go back to question above
- }
- }
- if ( userInt == otherInt )
- {
- printf ( "You entered: 12!\n" );
- printf ( "Would you like to start again? Y/N\n\n" );
- scanf ( "%s",&userInt ); /*It's important not to use '%d' here because '%d' means decimal number (but here we need a letter!)*/
- if ( userInt == 'Y' )
- {
- goto go1;
- }
- else if ( userInt == 'y' )
- {
- goto go1;
- }
- else if( userInt == 'N')
- {
- exit(0); //If either 'Y' or 'N' is enter, the program exits with 0
- }
- else if( userInt == 'n')
- {
- exit(0); //If either 'Y' or 'N' is enter, the program exits with 0
- }
- else
- {
- printf ("Invalid answer.\n");
- goto go2; //Go back to question above
- }
- }
- else
- {
- printf( "Can't you read? Try again!\n" );
- getchar();
- goto go1;
- }
- return 1;
- }
Add Comment
Please, Sign In to add comment