jc07 发表于 2021-11-5 11:49:39

新手求助

#include <stdio.h>

#define FANQIE 3.7
#define QINAN7
#define XIQIN 1.3
#define KONGXINCAI 8
#define YANGCONG 2.4
#define FANSIE 9
#define HUANGGUA 6.3
#define BAILUOBO 0.5
int main()
{
        floatprice
       
       
        price=(2*FANQIE+KONGXINCAI)*0.5;
        printf("小明需要支付的钱为%.2f元\n", price);
       
        price=(3* XIQIN+0.5*YANGCONG+5*HUANGGUA)*0.5;
        printf("小红需要支付的钱为%.2f元\n", price);
       
        price=(10*HUANGGUA+20*BAILUOBO)*0.5;
        printf=("小甲鱼需要支付的钱为%.2f元\n", price);
       
        return 0;
       
       
       
       
}   

看了半天不知道哪错了
       
       

tk3184020 发表于 2021-11-5 12:41:31

float price 那行没有;

jackz007 发表于 2021-11-5 13:28:02

本帖最后由 jackz007 于 2021-11-5 13:57 编辑

      有两处错误:
      floatprice                               ; // 行末添加分号 ;
      printf=("小甲鱼需要支付的钱为%.2f元\n", price) ; // 去掉 print 和 () 之间的等号 =

      下面是改好的代码:
#include <stdio.h>

#define FANQIE 3.7
#define QINAN7
#define XIQIN 1.3
#define KONGXINCAI 8
#define YANGCONG 2.4
#define FANSIE 9
#define HUANGGUA 6.3
#define BAILUOBO 0.5

int main()
{
      floatprice                                  ;
      price=(2*FANQIE+KONGXINCAI)*0.5               ;
      printf("小明需要支付的钱为%.2f元\n", price)   ;
      price=(3* XIQIN+0.5*YANGCONG+5*HUANGGUA)*0.5;
      printf("小红需要支付的钱为%.2f元\n", price)   ;
      price=(10*HUANGGUA+20*BAILUOBO)*0.5         ;
      printf("小甲鱼需要支付的钱为%.2f元\n", price) ;
      return 0                                    ;
}
      编译、运行实况:
D:\00.Excise\C>g++ -o x x.c

D:\00.Excise\C>x
小明需要支付的钱为7.70元
小红需要支付的钱为18.30元
小甲鱼需要支付的钱为36.50元

D:\00.Excise\C>、
页: [1]
查看完整版本: 新手求助