//**********************************88
//你有两万块钱去买家电,彩电,冰箱,洗衣机
//作者:
//日期:11.18
//版本:1.0
//*********************************************************************
#include<iostream.h>
int qian;
void caidian() //彩电函数
{
int i,j;
int cd[4]={1,2,3,4}; //cd彩电号{1号彩电,2号彩电,3号彩电,4号彩电}
int qs[4]={5000,5500,6000,12000}; //qs是彩电钱
for(j=1;j<=4;j++)
{
cout<<j<<"号"<<"彩电"<<"钱数是"<<qs[j-1]<<"元"<<endl; //qs[j-1]因为数组从0开始
//我定义从1开始的所以-1
}
cout<<"请选择:"<<endl;
cin>>i;
for(j=0;j<=3;j++)
{
if(i==cd[j])
qian-=qs[j]; //求剩余的钱数
}
cout<<"你还有"<<qian<<"钱"<<endl;
}
void bingxiang() //冰箱函数
{
int i,j;
int bx[4]={1,2,3,4}; //cd冰箱号{1号冰箱,2号冰箱,3号冰箱,4号冰箱}
int qianshu[4]={3200,3800,5500,10000};
for(j=1;j<=4;j++)
{
cout<<j<<"号"<<"冰箱"<<"钱数是"<<qianshu[j-1]<<"元"<<endl;
}
cout<<"请选择:"<<endl;
cin>>i;
for(j=0;j<=3;j++)
{
if(i==bx[j])
qian-=qianshu[j];
}
cout<<"你还有"<<qian<<"钱"<<endl;
}
void xiyiji()
{
int i,j;
int xyj[4]={1,2,3,4};
int qianshu[4]={4000,5000,6500,15000};
for(j=1;j<=4;j++)
{
cout<<j<<"号"<<"洗衣机"<<"钱数是"<<qianshu[j-1]<<"元"<<endl;
}
cout<<"请选择:"<<endl;
cin>>i;
for(j=0;j<=3;j++)
{
if(i==xyj[j])
qian-=qianshu[j];
}
cout<<"你还有"<<qian<<"钱"<<endl;
}
void jiemian(void)
{
cout<<"**********************************"<<endl;
cout<<"** 1、彩电 **"<<endl;
cout<<"** 2、冰箱 **"<<endl;
cout<<"** 3、洗衣机 **"<<endl;
cout<<"**********************************"<<endl;
}
void main(void)
{
int xuan;
char a;
cout<<"请输入你的钱数:"<<endl;
cin>>qian;
b:
cout<<"是否购买家电:y/n"<<endl;
cin>>a;
do
{
if(a=='y' || a=='Y')
{
jiemian();
cout<<"请选择家电:"<<endl;
cin>>xuan;
if(xuan==1)
caidian();
else if(xuan==2)
bingxiang();
else if(xuan==3)
xiyiji();
else
{
cout<<"输入有误:"<<endl;
goto b;
}
cout<<"是否继续购买:y/n"<<endl;
cin>>a;
}
else
break;
}while(1);
}