拐✘ 2022-11-05 16:02 采纳率: 100%
浏览 29
已结题

自己写了个c语言练习题,一直在报错,求帮看为什么

题目是 火车站对乘客退票收取一定的费用,收费的方法是:按票价每10元(不足10元按10元计算)收2元,2元及2元以下的不退,请使用手动输入票价,计算乘客的 应退金额并输出。

#include<stdio.h>
#include<windows.h>
void main()
{
double y,x,n;
printf("请您输入票价:");
scanf("%lf", &x);
y = x / 10;
if ((int)x % 10 == 0)
{
n = x-2 * y;
printf("应退金额为:'%lf'", n);
}
else if ((int)x % 10 != 0)
{
n = x-2 *(y+1);
printf("应退金额为:'%lf'", n);
}
else if (x <=2)
{
printf("暂不支持退票");
}
system("pause");
}

  • 写回答

1条回答 默认 最新

  • 谢玄. 2022-11-05 17:18
    关注

    main 是 int 类型的,不是void

    #include<stdio.h>
    #include<windows.h>
    int main() {
        double y, x, n;
        printf("请您输入票价:");
        scanf("%lf", &x);
        y = x / 10;
        if ((int)x % 10 == 0) {
            n = x - 2 * y;
            printf("应退金额为:'%lf'", n);
        } else if ((int)x % 10 != 0) {
            n = x - 2 * (y + 1);
            printf("应退金额为:'%lf'", n);
        } else if (x <= 2) {
            printf("暂不支持退票");
        }
        system("pause");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月14日
  • 已采纳回答 11月6日
  • 创建了问题 11月5日

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端