当前位置:首页 » 编程语言 » 自动售卖机1c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

自动售卖机1c语言

发布时间: 2023-06-16 19:03:45

1. 自动售货机c语言编程 急!!

#include "stdio.h"
#include "conio.h"

struct stDrink
{
float fPrice; // 价格
int iLeft; // 剩余数
};

void Pay(stDrink* pstPay)
{
float fPay = 0.0f;

if ( pstPay->iLeft<=0 )
{
printf("商品已经售完\r\n");
return;
}
while(1)
{
scanf("%f",&fPay);
if ( fPay<pstPay->fPrice )
{
printf("金额不足,请重新付费\r\n");
}
else if ( fPay>pstPay->fPrice)
{
printf("找零钱%.1f元,请收好\r\n",fPay-pstPay->fPrice);
break;
}
else
{
printf("付费成功\r\n");
break;
}
}
pstPay->iLeft--;
}

int main()
{
stDrink stCoca = {2.5f,5}; // 可乐
stDrink stOrage = {3.5f,5}; // 橙汁
stDrink stMilkTea = {5.0f,5}; // 奶茶

char cInput = 0;

while(1)
{
cInput = getch();
switch(cInput)
{
case '1':
// 可乐
printf("可乐2.5元,请付费\r\n");
Pay(&stCoca);
break;
case '2':
// 橙汁
printf("橙汁3.5元,请付费\r\n");
Pay(&stOrage);
break;
case '3':
// 奶茶
printf("奶茶5元,请付费\r\n");
Pay(&stMilkTea);
break;
case '#':
// 设备维修中
printf("设备维修中\r\n");
break;
case 'e':
// 退出程序
return 0;
}
}
return 0;
}

2. c语言,编写一个售货机(POS)计算程序,用于水果店售货员算账.苹果每千克3.2元,梨每千克1.96元,香

#include<stdio.h>
intmain(void)
{
floatp[4]={3.2,1.96,3,24};
floatw[4]={1.5,2,3,1.5};
floats=0;
inti;
for(i=0;i<4;i++)
s+=p[i]*w[i];
printf("%s%12s%12s%13s ","名称","单价","重量","应付价钱");
printf("--------------------------------------------- ");
printf("%s%12.2f%12.2f%13.3f ","苹果",p[0],w[0],p[0]*w[0]);
printf("%s%12.2f%12.2f%13.3f ","梨",p[1],w[1],p[1]*w[1]);
printf("%s%12.2f%12.2f%13.3f ","香蕉",p[2],w[2],p[2]*w[2]);
printf("%s%12.2f%12.2f%13.3f ","樱桃",p[3],w[3],p[3]*w[3]);
printf("--------------------------------------------- ");
printf("%s%37.2f ","总计",s);
printf("%s%37.2f ","付款",100.0);
printf("%s%37.2f ","找零",100.0-s);
return0;
}