S1E5课后作业第二题
#include <stdio.h>#define FQ 3.7
#define JL 7
#define XQ 3.7
#define KXC 8
#define YC 2
#define YOUCAI
#define HG 6
#define BLB 0.5
int main()
{
float xm;
float xh;
float xjy;
xm = (2 * FQ +KXC + YOUCAI) * 0.5;
xh = (3 * XQ + 0.5 * YC + 5 * HG) * 0.5;
xjy = (10 * HG + 20 * BLB) * 0.5;
printf("小明需要支付%2.f元\n",xm);
printf("小红需要支付%2.f元\n", xh);
printf("小甲鱼需要支付%2.f元\n", xjy);
return 0;
}
~
这样写报错:
2.c: In function ‘main’:
2.c:18: error: expected expression before ‘)’ token
2.c:22: error: stray ‘\357’ in program
2.c:22: error: stray ‘\274’ in program
2.c:22: error: stray ‘\214’ in program
2.c:22: error: expected ‘)’ before ‘xm’
是不是不能这样写?还是哪里搞错了? #defined YOUCAI 后面没东西呀 还有是不是22行标点符号有问题 chinggggg 发表于 2019-1-4 19:41
#defined YOUCAI 后面没东西呀
能编译了但是结果怎么是整数。。小数点后的没了
printf("小明需要支付%2.f元\n",xm);
printf("小红需要支付%2.f元\n", xh);
printf("小甲鱼需要支付%2.f元\n", xjy);
应该是%.2f
页:
[1]