我已經寫了一個程序,要求用戶輸入一個兩位數的號碼,並打印出英文單詞的號碼。 例子:程序打印一個號碼的英文單詞
Enter a two digit number: 45
You entered fourty-five
基本上,我所做的是我已經把switch
案例數爲10〜19,然後用於十位和另一個用於一個人的另一臺交換機的情況。
的問題是,輸入號碼,出於某種原因之後,在沒有打印You entered the number:
這裏經過任何顯示的代碼:
#include <stdio.h>
int main(void) {
int Num, Tens, Ones;
printf("Enter a Two Digit Number: ");
scanf("%d", &Num);
printf("You entered the number: ");
if (10 <= Num && Num >= 19) {
switch (Num) {
case 10: printf("Ten\n"); break;
case 11: printf("Eleven\n"); break;
case 12: printf("Twelve\n"); break;
case 13: printf("Thirteen\n"); break;
case 14: printf("Fourteen\n"); break;
case 15: printf("Fifteen\n"); break;
case 16: printf("Sixteen\n"); break;
case 17: printf("Seventeen\n"); break;
case 18: printf("Eighteen\n"); break;
case 19: printf("Nineteen\n"); break;
}
}
if (20 <= Num && Num >= 99) {
Tens = Num/10;
switch (Tens) {
case 2: printf("Twenty"); break;
case 3: printf("Thirty"); break;
case 4: printf("Fourty"); break;
case 5: printf("Fifty"); break;
case 6: printf("Sixty"); break;
case 7: printf("Seventy"); break;
case 8: printf("Eighty"); break;
case 9: printf("Ninety"); break;
}
}
Ones = Num % 10;
if (Ones == 0)
printf("\n");
else
if (1 <= Ones && Ones >= 9) {
printf("-");
switch (Ones) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
case 3: printf("Three"); break;
case 4: printf("Four"); break;
case 5: printf("Five"); break;
case 6: printf("Six"); break;
case 7: printf("Seven"); break;
case 8: printf("Eight"); break;
case 9: printf("Nine"); break;
}
printf("\n");
}
return 0;
}
所有情況都不對......累積獎金! – LPs
'(10 <= Num && Num> = 19)'你認爲這可能永遠是真的嗎?你可以通過一些基本的printf調試發現自己。 –
你不處理'0'。 – chqrlie