赞
踩
代码:
#include <stdio.h> #include <stdlib.h> #include <string> #include <iostream> using namespace std; int main() { //售货机只卖三种商品 // 薯片,可乐,面包 单价为 5元,3元,4元 初始数量都为10个 int shupians=10; int cokes=10; int breads=10; int Moneys=0; //记录营业额 cout<<"自动售货机系统启动"<<endl; while(true) { int n=0; cout<<"1.购买商品"<<endl; cout<<"2.补货"<<endl; cout<<"3.查询营业额度"<<endl; cin>>n; if(n==1) { while(true) { cout<<"请输入要购买的商品"<<endl; cout<<"1.薯片"<<endl; cout<<"2.可乐"<<endl; cout<<"3.面包"<<endl; cout<<"4.退出"<<endl; int a=0; int Count=0; cin>>a; if(a==1) { cout<<"请输入需要购买的数量"<<endl; cin>>Count; if(Count>shupians) { cout<<"数量超出库存,请重新选择"<<endl; } else { cout<<"总价为:"<<Count*5<<endl; cout<<"请投币取货"<<endl; cout<<"请输入投币金额"<<endl; int money=0; cin>>money; if(money<Count*5) { while(true) { cout<<"金额不足"<<endl; cout<<"1.继续投币"<<endl; cout<<"2.取消购买"<<endl; int g=0; cin>>g; if(g==1) { cout<<"输入投币金额"<<endl; int money2=0; cin>>money2; money+=money2; if(money>=Count*5) { Moneys+=Count*5; cout<<"购买成功"<<endl; cout<<"找零:"<<money-Count*5<<"元"<<endl; break; } }else if(g==2) { cout<<"找零:"<<money<<"元"<<endl; break; } } } } }else if(a==2) { cout<<"请输入需要购买的数量"<<endl; cin>>Count; if(Count>cokes) { cout<<"数量超出库存,请重新选择"<<endl; } else { cout<<"总价为:"<<Count*3<<endl; cout<<"请投币取货"<<endl; cout<<"请输入投币金额"<<endl; int money=0; cin>>money; if(money<Count*5) { while(true) { cout<<"金额不足"<<endl; cout<<"1.继续投币"<<endl; cout<<"2.取消购买"<<endl; int g=0; cin>>g; if(g==1) { cout<<"输入投币金额"<<endl; int money2=0; cin>>money2; money+=money2; if(money>=Count*3) { Moneys+=Count*3; cout<<"购买成功"<<endl; cout<<"找零:"<<money-Count*5<<"元"<<endl; break; } }else if(g==2) { cout<<"找零:"<<money<<"元"<<endl; break; } } } } }else if(a==3) { cout<<"请输入需要购买的数量"<<endl; cin>>Count; if(Count>breads) { cout<<"数量超出库存,请重新选择"<<endl; } else { cout<<"总价为:"<<Count*5<<endl; cout<<"请投币取货"<<endl; cout<<"请输入投币金额"<<endl; int money=0; cin>>money; if(money<Count*4) { while(true) { cout<<"金额不足"<<endl; cout<<"1.继续投币"<<endl; cout<<"2.取消购买"<<endl; int g=0; cin>>g; if(g==1) { cout<<"输入投币金额"<<endl; int money2=0; cin>>money2; money+=money2; if(money>=Count*4) { Moneys+=Count*4; cout<<"购买成功"<<endl; cout<<"找零:"<<money-Count*5<<"元"<<endl; break; } }else if(g==2) { cout<<"找零:"<<money<<"元"<<endl; break; } } } } } else if(a==4) { break; } else { cout<<"操作有误,重新操作"<<endl; } } } else if(n==2) { while(true) { cout<<"请输入要购买的商品"<<endl; cout<<"1.薯片"<<endl; cout<<"2.可乐"<<endl; cout<<"3.面包"<<endl; cout<<"4.退出"<<endl; int a=0; cin>>a; if(a==1) { cout<<"请输入上货数量"<<endl; int Count=0; cin>>Count; shupians+=Count; cout<<"薯片数量:"<<shupians<<endl; }else if(a==2) { cout<<"请输入上货数量"<<endl; int Count=0; cin>>Count; cokes+=Count; cout<<"可乐数量:"<<cokes<<endl; } else if(a==3) { cout<<"请输入上货数量"<<endl; int Count=0; cin>>Count; breads+=Count; cout<<"面包数量:"<<breads<<endl; } else if(a==4) { break; } else { cout<<"操作有误,请重新操作"<<endl; } } } else if(n==3) { cout<<"营业额为:"<<Moneys<<endl; } else { cout<<"操作有误,请重新选择"<<endl; } } return 0; }
效果图:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。