题目是 火车站对乘客退票收取一定的费用,收费的方法是:按票价每10元(不足10元按10元计算)收2元,2元及2元以下的不退,请使用手动输入票价,计算乘客的 应退金额并输出。
#include
#include
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");
}
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");
}