Skip to content

Commit

Permalink
Add grade exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
zachwill committed Sep 11, 2011
1 parent 766dfdd commit 6138bfb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions 06_02_grades.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Excercise 6.2
// =============
//
// Given a numeric grade, print the letter.

#include <stdio.h>

int grade;

int main(int argc, const char *argv[]) {
if (argc == 2) {
grade = atoi(argv[1]);
} else {
printf("You didn't pass a grade argument.");
return 0;
}

if (grade == 100) {
printf("F");
} else if (grade >= 90) {
printf("A");
} else if (grade >= 80) {
printf("B");
} else if (grade >= 70) {
printf("C");
} else if (grade >= 60) {
printf("D");
} else {
printf("F");
}

return 0;
}

0 comments on commit 6138bfb

Please sign in to comment.