⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lx5_9.c

📁 学习算法的资料书
💻 C
字号:
#define APPLE 1.9
#define BANANA 2.2
#define WATERMELON 2.0
main()
{float apple,banana,peach, price, paid, sum, weight;
 int key,flag;
 sum=0;
 flag=1;
 do
    {printf("input fruit key:");
     scanf("%d",&key);
     switch(key)
     {case 0: flag=0;break;
      case  1: printf("input apples' weight:"); scanf("%f",&weight);break;
      case  2: printf("input bananas'weight:"); scanf("%f",&weight); break;
      case  3: printf("input watermelon's weight:");
	              scanf("%f",&weight);
	              break;
      default: if (key!=0)
		    {printf("no this fruit\n");
		     flag=0;
		    }
     }
     if(flag!=0)
	  {switch(key)
	     {case  1: price=weight*APPLE; 
printf("it's price is %4.2f * %5.2f = %5.2f\n",APPLE,weight,price);
break;
	      case  2: price=weight*BANANA;
printf("it's price is %4.2f * %5.2f = %5.2f\n",BANANA,weight,price);break;
	      case  3: price=weight*WATERMELON;
printf("it's price is %4.2f * %5.2f = %5.2f\n",WATERMELON,weight,price);
	     }
	 sum=sum+price;
	}
    }while (key!=0);
    printf("the total price is %5.2f\n",sum);
    printf("input the custom paid:");
    scanf("%f",&paid);
    printf("return to %5.2f\n",paid-sum);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -