gpt4 book ai didi

c - 打印一个数字的英文单词的程序

转载 作者:行者123 更新时间:2023-11-30 18:24:49 25 4
gpt4 key购买 nike

我编写了一个程序,要求用户输入两位数,然后打印出该数字的英文单词。示例:

Enter a two digit number: 45
You entered fourty-five

基本上,我所做的就是为数字 10 到 19 放置一个 switch 盒,然后为 10 号使用另一个开关盒,为 1 号使用另一个开关盒。

问题是,输入号码后,由于某种原因,打印后没有显示任何内容您输入了号码:

这是代码:

#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;
}

最佳答案

您的条件是错误的,并且在正常执行中将始终为假。

尝试这些修改:

  • 10 <= Num && Num >= 19 -> 10 <= Num && Num <= 19
  • 20 <= Num && Num >= 99 -> 20 <= Num && Num <= 99
  • 1 <= Ones && Ones >= 9 -> 1 <= Ones && Ones <= 9

关于c - 打印一个数字的英文单词的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35749874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com