📄 水果收银机.txt
字号:
水果收银机
编写收银机程序:为某个水果店售货员算账,苹果每斤2.8元,香蕉每斤1.7元,芒果每斤6.5元。要求输入各种水果的重量,打印应付的钱数,再输入顾客付款数,打印应找的钱数。
分析:因为有不同种类的水果,需要用switch语句进行选择;而且这个水果店收银机一直是开着的,直到关门才结束,需要用循环语句保证程序一直运行。程序包括while,if-else和switch语句的嵌套。
#include<iostream.h>
const float APPLE=2.8;
const float BANANA=1.7;
const float MANGO=6.5;
void main()
{ int c;
char stop='n';
double weight,pay,money,change;
cout<<"welcome to our fruit store,press any key to begin!(^_^)"<<endl;
while(1)
{ cout<<"--------------press \'y\' to close the fruit store-------\n";
stop=getchar();
if(stop=='y'||stop=='Y') break;
else
{ cout<<"Please choose you fruit class"<<endl;
cout<<"APPLE \t----1 \t 2.8yuan/500g\n
BANANA \t----2 \t 1.7yuan/500g\n
MANGO \t----3 \t 6.5yuan/500g\n";
cin>>c;
cout<<"Please input the weight:";
cin>>weight;
switch(c)
{ case 1: pay=weight * APPLE; break;
case 2: pay=weight * BANANA; break;
case 3: pay=weight * MANGO; break;
default: cout<<"choose error \n"; goto loop;
}
cout<<"You should pay"<<pay<<"yuan.\n please input your money:";
cin>>money;
change=money-pay;
cout<<"\n Your money is \t"<<money<<", you shoule pay \t"<<pay<<".\n Your change is"<<change<<endl;
loop:cout<<"Thank you! ----- next customer,please!\n";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -