從屏幕上輸入一個學生的成績(0-100),對學生成績進行評定:
<=60為"E"
60~69為"D"
70~79為"C"
80~89為"B"
90以上為"A"
<0或>100提示成績輸入出錯
實現代碼:
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int socre; 7 printf("plz input a score:"); 8 scanf("%d",&socre); 9 //printf("socre:%d",socre); 10 if (socre > 100 || socre < 0) 11 { 12 printf("plz input socre between 0 and 100"); 13 return -1; 14 } 15 socre /= 10; 16 switch(socre) 17 { 18 case 9: 19 case 10: 20 printf("A"); 21 break; 22 case 8: 23 printf("B"); 24 break; 25 26 case 7: 27 printf("C"); 28 break; 29 case 6: 30 printf("D"); 31 break; 32 default: 33 printf("E"); 34 } 35 return 0; 36 }
沒有解決的問題,在輸入字母等字符時,並沒有報錯,有待進一步優化!
使用的環境未qt!
