我正在写一个程序,允许用户制作一个3对3梦幻生物的锦标赛。锦标赛的实际战斗部分运行良好,但在我的最后一行cout代码说谁赢得了最后一场比赛之后,当我试图输出排名时,会出现一个空格,就像出现cin时一样,但如果输入任何内容,则什么也不会发生。我相信有更好的方法来绘制我的地图,但我不能理解为什么我的cout中没有变量的顶行也不会出现。这只是战斗结束后代码的一部分。points和standing都是int,int map。
for (int i=1; i<7;i++)
{
for (int j=1; j<7;i++)
{
if ((points[i]==points[j])&&(i!=j))
{
int tie=rand()%2;
if (tie==0)
{
points[i]=points[i]+1;
}
else
{
points[j]=points[j]+1;
}
}
}
}
for (int i=1;i<7;i++)
{
standing[(points[i])]=i;
}
map <int,int>::iterator k;
k=standing.begin();
cout << "These are the final standings. \n";
cout << "Please note fighters 1-3 are player 1 and \n";
cout << "4-6 are from player 2. \n";
cout << "In first place is fighter #" << k->second;
cout << " with " << k->first << "points \n";
k++;
cout << "In second place is fighter #" << k->second;
cout << " with " << k->first << "points \n";
k++;
cout << "In third place is fighter #" << k->second;
cout << " with " << k->first << "points \n";
return 0;发布于 2014-08-31 10:49:29
for (int j=1; j<7;i++)是一个无限循环--您最后可能指的是j++。因此,永远不会执行cout行。
https://stackoverflow.com/questions/25588515
复制相似问题