C++ 15(家电)

 //**********************************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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值