7
Expressions booléennes
- #include <stdlib.h>
- #include <stdio.h>
- main() {
- char c;
- printf( "Enter (y)es or (n)o: " );
- if ( scanf("%c", &c ) == 1 )
- if ( c == 'Y' || c == 'y' )
- printf("Yes\n");
- else if ( c == 'N' || c == 'n' )
- printf("No\n");
- else
- printf("What?\n");
- exit( 0 );
- }
$ gcc -o yesno yesno.c
$ ./yesno
Enter (y)es or (n)o: y
Yes
$ ./yesno
Enter (y)es or (n)o: n
No
$ ./yesno
Enter (y)es or (n)o: No
No
$ ./yesno
Enter (y)es or (n)o: oui
What?
Commentaires