C语言学习9:

经过千辛万苦的修改和调试我终于成功了。。。。
我放弃了数组的想法,因为自定义函数的返回值如果是数组的话好像会出错误,所以就返回每种蔬菜的总费用,之后进行逆运算来得到正确答案了。我有预感,像这样用逆运算的方法我感觉以后可能会用到好多。。。。。

闲话到这下面是程序的源代码:
#include<stdio.h>
#define Artichoke 2.05
#define Vulgaris 1.15
#define Carrort 1.09
float artichoke(float);
float vulgaris(float);
float carrort(float);
float artichoke(float pounds)
{
 float pound,price;
 printf("please enter the pounds:\n");
 scanf("%f",&pound);
 price=pound*Artichoke;
 return price;
}
float vulgaris(float pounds)
{
 float pound,price;
 printf("please enter the pounds:\n");
 scanf("%f",&pound);
 price=pound*Vulgaris;
 return price;
}
float carrort(float pounds)
{
 float pound,price;
 printf("please enter the pounds:\n");
 scanf("%f",&pound);
 price=pound*Carrort;
 return price;
}
main()
{
 char order,answer;
 float pounds,A,B,C;
 printf("Enter a to order Artichoke:%.2fdollars each pound;\n",Artichoke);
 printf("Enter b to order Vulgaris:%.2fdollars each pound;\n",Vulgaris);
 printf("Enter c to order Carrort:%.2fdollars each pound;\n",Carrort);
 printf("Enter q to close the system:\n");
 
 
    loop1:printf("Please enter the word:\n");
 scanf("%s",&order);//循环块1
 
 //
        switch(order)
  {
  case 'a':A=A+artichoke(pounds);break;
  case 'b':B=B+vulgaris(pounds);break;
  case 'c':C=C+carrort(pounds);break;
  case 'q':goto loop2;break;
  default :printf("Please enter right word!\n");
  case 1:goto loop1;
  }
   
 printf("Would you want to order again?\n");//重选项目
 printf("Y or N \n");
 scanf("%s",&answer);
 {
 if (answer=='Y'||answer=='y')
 goto loop1;
 else if (answer=='N'||answer=='n')
 goto loop3;}
    //
 loop3:
 
 printf("The Artichoke is ordered %.2fpounds,the price is %.2fdollars;\n",A/Artichoke,A);
    printf("The Vulgaris is ordered %.2fpounds,the price is %.2fdollars;\n",B/Vulgaris,B);
    printf("The Carrort is ordered %.2fpounds,the price is %.2fdollars.\n",C/Carrort,C);//分项显示
 
 printf("The whole price are %.2fdollars \n",A+B+C);
    printf("The whole vegetables are %.2fpounds \n",(A/Artichoke)+(B/Vulgaris)+(C/Carrort));//总项显示
   
 loop2:printf("Thank for your usering!");
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值