-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment_3.txt
51 lines (46 loc) · 1.19 KB
/
Assignment_3.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Created by Zhang Xingjian DC027486
//
#include <stdio.h>
#include <malloc.h>
char* grade(int a);
int main(void){
int score;
char* grades;
printf("Enter your exam mark (0..100):");
scanf("%d", &score);
grades = (char*)malloc(sizeof(grades));
grades = grade(score);
printf("Your grade is %s", grades);
free(grades);
return 0;
}
char* grade(int a){
char* grades;
grades = (char*)malloc(sizeof(grades));
switch(a){
case 93 ... 100:
grades = "A"; break;
case 88 ... 92:
grades = "A-"; break;
case 83 ... 87:
grades = "B+"; break;
case 78 ... 82:
grades = "B"; break;
case 73 ... 77:
grades = "B-"; break;
case 68 ... 72:
grades = "C+"; break;
case 63 ... 67:
grades = "C"; break;
case 58 ... 62:
grades = "C-"; break;
case 53 ... 57:
grades = "D"; break;
case 50 ... 52:
grades = "D-"; break;
case 0 ... 49:
grades = "F"; break;
default: grades = "Invalid grade!";
}
return grades;
}