函数入口处停止了
运行没有问题,就是在主函数的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++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 2:
if((sum-1)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 3:
if((sum-1)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; returnpnum ;}break;
case 4:
if((sum-2)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 5:
if((sum-2)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;} break;
case 6:
if((sum-3)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 7:
if((sum-3)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 8:
if((sum-3)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 9:
if((sum-4)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 10: if((sum-4)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
default:break;
}
}
return pnum;
}
int main()
{
intbalance , money=0,sum=0 ;
intnum={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;
} 。 。 首先把代码发完整,然后重新描述一下你的问题
#include <iostream>
usingnamespace std;
void VendingMachine()
{
cout<<"-------------------------------------------------------------------"<<endl;
cout<<" 1 2 3 4 5 "<<endl;
cout<<"Table-water "<<" Table-water "<<" Table-water "<<" Coca-cola "<<" Milk"<<endl;
cout<<" 1元 "<<" 1元 "<<" 1元 "<<" 2元 "<<" 2元 "<<endl;
cout<<endl;
cout<<" 6 7 8 9 10 "<<endl;
cout<<" Beer "<<"Orange-Juice "<<" Sprite "<<" Oolong-Tea "<<" Green-Tea "<<endl;
cout<<" 3元 "<<" 3元 "<<" 3元 "<<" 4元 "<<" 4元 "<<endl;
cout<<endl;
}
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++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 2:
if((sum-1)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 3:
if((sum-1)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; returnpnum ;}break;
case 4:
if((sum-2)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 5:
if((sum-2)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;} break;
case 6:
if((sum-3)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 7:
if((sum-3)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 8:
if((sum-3)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 9:
if((sum-4)>0)
{ sum-=1;pnum++;}
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
case 10: if((sum-4)>0)
{ sum-=1;pnum++; }
else
{ cout<<"余额为"<<sum<<endl; return pnum;}break;
default:break;
}
}
return pnum;
}
int main()
{
intbalance , money=0,sum=0 ;
intnum={0,0,0,0,0,0,0,0};
int *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;
} 主函数在输入的时候当输入负一时跳出循环,然后就停下来了,不能进入到Selection里接受第二次输入,调试发现是在p=Selection(sum,num)上一条语句停下来,就执行不了了 人造人 发表于 2020-3-30 00:20
首先把代码发完整,然后重新描述一下你的问题
好了 人造人 发表于 2020-3-30 00:20
首先把代码发完整,然后重新描述一下你的问题
好了 尊贵vip用户 发表于 2020-3-30 09:44
好了
页:
[1]