自动售货机程序
默认分类 2009-07-24 02:05 阅读42 评论0 字号: 大大 中中 小小 第一次认真编写程序,竟然这么长,疯了,呵呵,幸好完成老师的任务了!喔耶!
#include"stdio.h"
char yn,cho,cho1,cho2;
int n=0,i=100,j=100,k=100,i1=0,j1=0,k1=0,i2=100,m=0,
j2=100,k2=100,m1=0,m2=0,m3=0,ly5=0,ly1=0,charge5=10,charge1=10,
change5=0,change1=0,num10;long password,g;
void xiaoshou()
{FILE * fp;
/*
choose the action you want.
whether you would like to buy things or not.
if you would like to buy things printf y
if you don't want to buy things printf n
*/
if(yn=='y')
{
{clrscr();
printf("\n\n\n\n\n\n");
printf(" |===========================================================================|\n");
printf(" | choose the kind of the things you want and pay foy it please! |\n");
printf(" |===========================================================================|\n");
scanf("%c",&cho);
if(charge5>0&&charge1>=0)
/*
if the number of the 5 yuan is larger than that of the 1 yuan ,
you will get 5 yuan instead of that of 5 piece of 1 yuan
*/
{
if(charge5>=charge1)
{
charge5=10+change5;
charge1=10+change1;
charge5-=ly5;
charge1-=ly1;
if(cho=='a') {
if(charge5>=1&&charge1>=3&&i2>0)
{printf(" return 8 yuan please!\n");
i2--;
m1++;
m=m1+m2+m3;
getch();
ly5+=1;
ly1+=3;
if((fp=fopen("D:\\pxy.txt","a"))==NULL)
{
printf("cannot open the file!");
exit(0);
}
fprintf(fp,"a,%d\ta piece of 5 yuan and 3 pieces of 1 yuan\n\tnow the all number is %d\n",m1,m);
fclose(fp);
}
else {
printf("I'm sorry the good of A has been sold out!\n");
getch();
}
}
if(cho=='b') { if(charge5>=1&&charge1>=2&&j2>0)
{ printf(" return 7 yuan please!\n");
j2--;
m2++;
m=m1+m2+m3;
getch();
ly5+=1;
ly1+=2;
if((fp=fopen("D:\\pxy.txt","a"))==NULL)
{
printf("cannot open the file!");
exit(0);
}
fprintf(fp,"b,%d\ta piece of 5 yuan and 2 pieces of 1 yuan\n\tnow the all number is %d\n",m2,m);
fclose(fp);
}
else {
printf("I'm sorry the good of A has been sold out!\n");
getch();
}
}
if(cho=='c') { if(charge1>=4&&k2>0)
{printf(" return 4 yuan please!\n");
k2--;
m3++;
m=m1+m2+m3;
getch();
ly1+=4;
if((fp=fopen("D:\\pxy.txt","a"))==NULL)
{
printf("cannot open the file!");
exit(0);
}
fprintf(fp,"c,%d\t4 pieces of 1 yuan\n\tnow the all number is %d\n",m3,m);
fclose(fp);
}
else {
printf("I'm sorry the good of A has been sold out!\n");
getch();
}
}
}
/*
if the number of the 5 yuan is smaller than that of the 1 yuan ,
you will get 5 1 yuan instead of that of one 5 yuan.
*/
if(charge5<charge1)
{
charge5=10+change5;
charge1=10+change1;
charge5-=ly5;
charge1-=ly1;
if(cho=='a') {
if(charge1>=8&&i2>0)
{
printf(" return 8 yuan please!\n");
i2--;
m1++;
m=m1+m2+m3;
getch();
ly1+=8;
if((fp=fopen("D:\\pxy.txt","a"))==NULL)
{
printf("cannot open the file!");
exit(0);
}
fprintf(fp,"a,%d\t8 pieces of 1 yuan \n\tnow the all number is %d\n",m1,m);
fclose(fp);
}
else {if(charge5>=1&&charge1>=3)
{
printf(" return 8 yuan please!\n");
i2--;
m1++;
m=m1+m2+m3;
getch();
ly5+=1;
ly1+=3;
if((fp=fopen("D:\\pxy.txt","a"))==NULL)
{
printf("cannot open the file!");
exit(0);
}
fprintf(fp,"a,%d\ta piece of 5 yuan,3 pieces of 1 yuan \n\tnow the all number is %d\n",m1,m);
fclose(fp);
}
else{ printf("I'm sorry the good of A has been sold out!\n");
getch();
}}
}
if(cho=='b') {if(charge1>=7&&j2>0)
chengxusheji.rar_无人售货_自动售货机
版权申诉
20 浏览量
2022-09-21
06:12:06
上传
评论
收藏 2KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+
最新资源
- hdmi in视频采集,输出到hdmi out, 支持HDMI指令控制,支持TFTP远程下载图片
- 批量word文件内容替换工具1.0 (批量实现多个 Word 文档文件文字替换利器).exe
- Cartoon GUI Pack 1.2.zip
- 【数据集和代码】基于加速度传感器的步态识别行人分类实验(可做步态识别)
- 我分享个魔兽内存修改器
- Python毕业设计基于Django的网易云数据分析可视化大屏系统的设计与实现+使用说明+全部资料(优秀项目).zip
- mp3 idv2,idv1,frame分析工具
- 鹈鹕优化算法POA MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用
- Python毕业设计基于Django的网易云数据分析可视化大屏系统的设计与实现+使用说明+全部资料(高分项目).zip
- 蛇优化算法SO MATLAB源码, 应用案例为函数极值求解以及优化svm进行分类,代码注释详细,可结合自身需求进行应用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈