2401_87796672 2024-10-08 23:34 采纳率: 0%
浏览 5

出现这种问题应该怎么办呀

为什么它无法识别total coins

img


1 #include <stdio.h>
2
int main( )3
/begin/ int cash; printf("
");
scanf("%d",&cash);
int twenty =cash / 20; cash %= 20;
10 int ten = cash / 10;
11 cash %= 10;
12 int five =cash/5;
13 cash %=5;
14 int one =cash;
15 int total coins=twenty+ten+five+one;
17 16 printf(" return 0; %d \n",total coins);
1819
20 /
************
end************/
return 0;
24

编译器(6)资源编译日志调试搜索结果 Console关闭
行 列 单元 信息
15 12 C:\Users\周?劳?\Desktop\未??1.c [Error| expected '=,'.. ., 'asm' or 'attribute_'before 'coins'
15 12 C:\Users\周?劳?\Desktop\未??1.c [Error] 'coins'undeclared (first use in this function)
15 12 C:\Users\周?劳?\Desktop\未??1.c [Note| each undeclared identifier is reported only once for each function it appears in
16 40 C:\Users?范?彤\Desktop?批?名1.c [Error] total' undeclared (first use in this function)
16 45 C:\Users?苊?彤\Desktop?疵?名1.c [Error] expected ')'before 'coins'
行:24 列:3 已选择:0 总行数:24 长度:410插入 在0秒内完成解析
搜索
-456789
2223

  • 写回答

1条回答 默认 最新

  • 一轮明月照丘壑 2024-10-08 23:35
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    从你提供的代码和错误信息来看,有几个问题需要解决:

    1. 在声明变量total coins时,变量名中间不应该有空格。正确的做法应该是int total_coins
    2. 在使用变量total_coins之前,需要确保它已经被声明和初始化。
    3. 在使用变量之前,确保它们所在的代码块(例如函数)已经定义了这些变量。

    针对你提供的代码,以下是修改后的版本:

    #include <stdio.h>
    
    int main() {
        int cash;
        printf("请输入您持有的现金数:");
        scanf("%d", &cash);
        
        int twenty = cash / 20;      cash %= 20;
        int ten = cash / 10;          cash %= 10;
        int five = cash / 5;          cash %= 5;
        int one = cash;
        
        int total_coins = twenty + ten + five + one;
        printf("最少需要%d张零钱。\n", total_coins);
        
        return 0;
    }
    

    关于你提供的错误信息,它们主要是由于变量未声明或声明格式错误导致的。确保按照上述修改进行更正,并重新编译程序。

    评论

报告相同问题?

问题事件

  • 创建了问题 10月8日