lesson 8 showgrad c
[[lesson_8_showgrad_c]] last edit on
Aug 10, 2005
3:36 AM
by rescued_by_c
[user02@FC4 Lesson08]$ cat -n showgrad.c
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 100
You got an A!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 90
You got an A!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 89
You got a B!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 79
You got a C
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 69
Your grade was a D
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 59
You failed the test
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: -20
You failed the test
1 #include <stdio.h>
2
3 int main(void)
4 {
5 int test_score;
6
7 printf("Type in your test score and press Enter: ");
8 scanf("%d", &test_score);
9
10 if (test_score >= 90)
11 printf("You got an A!\n");
12 else if (test_score >= 80)
13 printf("You got a B!\n");
14 else if (test_score >= 70)
15 printf("You got a C\n");
16 else if (test_score >= 60)
17 printf("Your grade was a D\n");
18 else
19 printf("You failed the test\n");
20
21 return 0;
22 }
[user02@FC4 Lesson08]$ gcc -o showgrad showgrad.c[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 100
You got an A!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 90
You got an A!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 89
You got a B!
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 79
You got a C
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 69
Your grade was a D
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: 59
You failed the test
[user02@FC4 Lesson08]$ ./showgrad
Type in your test score and press Enter: -20
You failed the test