#include <stdio.h>
int main(void) {
int b,a;
printf("Enter a numerical grade: ");
scanf("%1d%1d", &a, &b);
switch (a){
case 1:
case 2:
case 3:
case 4:
case 5:
printf("Letter grade: F");
break;
case 6:
printf("Letter grade: D");
break;
case 7:
printf("Letter grade: C");
break;
case 8:
printf("Letter grade: B");
break;
case 9:
printf("Letter grade: A");
break;
}
return 0;
}
是說,那個 b 要做什麼用
#include <stdio.h>
int main(void) {
int b,a;
printf("Enter a numerical grade: ");
scanf("%d %d", &a, &b);
switch (a){
case 0:
printf("case 0");
break;
case 1:
case 2:
case 3:
case 4:
case 5:
printf("Letter grade: F");
break;
case 6:
printf("Letter grade: D");
break;
case 7:
printf("Letter grade: C");
break;
case 8:
printf("Letter grade: B");
break;
case 9:
printf("Letter grade: A");
break;
case 100:
printf("Case 100");
break;
}
return 0;
}
謝謝,我原本想說打兩個數字分開判定
這個程式這樣沒辦法判定其他的
照您的寫法變成只能夠判定0和100
請問我該如何修改程式使其能判斷100和0? 謝謝
題目就是這樣,謝謝
那是我寫的不夠清楚sorry,我是想要都能夠判斷
所以要都能夠判斷那些數字?
上面的程式已經可以判斷0..9和100
100到90 89到80 79到70 69到60
我原本的程式無法判定0跟100
#include <stdio.h>
int main(void) {
int b,a;
printf("Enter a numerical grade: ");
scanf("%d %d", &a, &b);
switch (a) {
case 0 ... 59:
printf("Letter grade: F");
break;
case 60 ... 69:
printf("Letter grade: D");
break;
case 70 ... 79:
printf("Letter grade: C");
break;
case 80 ... 89:
printf("Letter grade: B");
break;
case 90 ... 100:
printf("Letter grade: A");
break;
}
return 0;
}
這個程式輸入一個數字無法執行,請問該如何修改成一個數字就能執行
Input Data:
Except:
Actual result:
Enter a numerical grade:
#include <stdio.h>
int main(void) {
int b,a;
printf("Enter a numerical grade: ");
scanf("%d", &a);
switch (a) {
case 0 ... 59:
printf("Letter grade: F");
break;
case 60 ... 69:
printf("Letter grade: D");
break;
case 70 ... 79:
printf("Letter grade: C");
break;
case 80 ... 89:
printf("Letter grade: B");
break;
case 90 ... 100:
printf("Letter grade: A");
break;
}
return 0;
}
太感謝你了,真的很謝謝
%d直接判斷整個數字不好嗎?
為什麼一定要用%1d?