本文目录一览:
c程序编写一个水果店售货员算账的程序
#includestdio.h
void main()
{
float n[4],apple=2.5,pear=1.8,banana=2,orange=1.6,price,charge,money;
printf("请输入水果重量苹果 鸭梨 香蕉 橘子 (不买的水果请输入0): \n");
int i;
for(i=0;i4;i++)scanf("%f",n[i]);
printf("应付钱 %.2f 元\n",price=apple*n[0]+pear*n[1]+banana*n[2]+orange*n[3]);
printf("请输入付款数:");scanf("%f",money);
printf("应找钱 %.2f 元\n",money-price);
}
c语言,编写一个售货机(POS)计算程序,用于水果店售货员算账.苹果每千克3.2元,梨每千克1.96元,香
#include stdio.h
int main(void)
{
float p[4] = {3.2, 1.96, 3, 24};
float w[4] = {1.5, 2, 3, 1.5};
float s = 0;
int i;
for(i=0;i4;i++)
s+= p[i]*w[i];
printf("%s%12s%12s%13s\n", "名称", "单价", "重量", "应付价钱");
printf("---------------------------------------------\n");
printf("%s%12.2f%12.2f%13.3f\n","苹果", p[0], w[0], p[0]*w[0]);
printf("%s%12.2f%12.2f%13.3f\n","梨 ", p[1], w[1], p[1]*w[1]);
printf("%s%12.2f%12.2f%13.3f\n","香蕉", p[2], w[2], p[2]*w[2]);
printf("%s%12.2f%12.2f%13.3f\n","樱桃", p[3], w[3], p[3]*w[3]);
printf("---------------------------------------------\n");
printf("%s%37.2f\n", "总计", s);
printf("%s%37.2f\n", "付款", 100.0);
printf("%s%37.2f\n", "找零", 100.0 - s);
return 0;
}
问一道关于记账的c语言程序
#includestdio.h
void fun(){
int i, ch; float price = 9.8, in_price, total = 0; while (1){
printf("\n1.算账模式\n2.算账\n3.退出\n");
scanf("%d", i);
switch (i){
case 1://算账模式
{
do{
printf("应付款金额 %f 元.\n付款金额:", price);
scanf("%f", in_price);
printf("实际付款金额%f,应找零金额 %f 元.\n", in_price, in_price - price);
total += price;
scanf("%d", ch);
} while (ch != -1);
break;
}
case 2:{
printf("收款总额:%6.2f 元.\n", total); break;
}
case 3:
exit(0);
}
}
}
void main()
{
fun();
}