|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
运行没有问题,就是在主函数的Selection函数入口处停止(调试时停在那)
int *Selection(int sum ,int *pnum)
{
int sel=0;
while (sum>0|sel!=-1);
{
VendingMachine();
cout<<"输入按钮数字即可选择对应的饮料(输入 -1 结束)"<<endl;
cin>>sel;
switch(sel)
{
case 1 :
if(sum-1>0)
{ sum-=1; pnum[0]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 2:
if((sum-1)>0)
{ sum-=1; pnum[0]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 3:
if((sum-1)>0)
{ sum-=1; pnum[0]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum ;}break;
case 4:
if((sum-2)>0)
{ sum-=1; pnum[1]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 5:
if((sum-2)>0)
{ sum-=1; pnum[2]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;} break;
case 6:
if((sum-3)>0)
{ sum-=1; pnum[3]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 7:
if((sum-3)>0)
{ sum-=1; pnum[4]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 8:
if((sum-3)>0)
{ sum-=1; pnum[5]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 9:
if((sum-4)>0)
{ sum-=1; pnum[6]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 10: if((sum-4)>0)
{ sum-=1; pnum[7]++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
default:break;
}
}
return pnum;
}
int main()
{
int balance , money=0, sum=0 ;
int num[8]={0,0,0,0,0,0,0,0} , *p;
cout<<"请投入纸币(接受 1元 2元 5元 10元,超过则直接退还)"<<endl;
while( money!=-1)
{
cin>>money;
if(money==1|money==2|money==5|money==10)
sum+=money;
}
cout<<"您投入的纸币总额为"<<sum<<endl;
p=Selection(sum,num);
return 0;
}
|
|