C语言学习9:

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

闲话到这下面是程序的源代码:
#include
#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",£);
 price=pound*Artichoke;
 return price;
}
float vulgaris(float pounds)
{
 float pound,price;
 printf("please enter the pounds:\n");
 scanf("%f",£);
 price=pound*Vulgaris;
 return price;
}
float carrort(float pounds)
{
 float pound,price;
 printf("please enter the pounds:\n");
 scanf("%f",£);
 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;
}

你可能感兴趣的:(C语言学习)