4

Read in a note and convert it in a letter

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. main() {
  5.     int note;
  6.  
  7.     printf("Enter your note [0-100]: ");
  8.     if( scanf("%d", &note) != 1 )
  9.         exit(1);
  10.     if( note > 100 || note < 0 ) {
  11.         printf("Try again!\n");
  12.         exit(1);
  13.     }
  14.     switch( note / 10 ) {
  15.         case 0:
  16.             note = 'F';
  17.             break;
  18.         case 10:
  19.         case 9:
  20.             note = 'A';
  21.             break;
  22.         case 8:
  23.             note = 'B';
  24.             break;
  25.         case 7:
  26.             note = 'C';
  27.             break;
  28.         case 6:
  29.             note = 'D';
  30.             break;
  31.         default:
  32.             note = 'E';
  33.             break;
  34.     }
  35.     printf("You get a %c!\n", note);
  36.  
  37.     exit( 0 );
  38. }
$ 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!

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].