7
Lire une note et la convertir en lettre
- #include <stdlib.h>
- #include <stdio.h>
- main() {
- int note;
- printf("Enter your note [0-100]: ");
- if( scanf("%d", ¬e) != 1 )
- exit(1);
- if( note > 100 || note < 0 ) {
- printf("Try again!\n");
- exit(1);
- }
- switch( note / 10 ) {
- case 0:
- note = 'F';
- break;
- case 10:
- case 9:
- note = 'A';
- break;
- case 8:
- note = 'B';
- break;
- case 7:
- note = 'C';
- break;
- case 6:
- note = 'D';
- break;
- default:
- note = 'E';
- break;
- }
- printf("You get a %c!\n", note);
- exit( 0 );
- }
$ gcc -o note note.c
$ ./note
Enter your note [0-100]: 85
You get a B!
$ ./note
Enter your note [0-100]: 200
Try again!
Commentaires