【发布时间】:2014-08-31 02:37:49
【问题描述】:
我正在编写一个程序,允许用户进行 3 对 3 幻想生物的锦标赛。比赛的实际战斗部分运行良好,但在我最后一句说谁赢得了最后一场战斗时,当我尝试输出排名时,一个空白区域就像出现 cin 时一样,但如果输入任何东西都没有任何反应。我确信有更多优雅的方法来制作我的地图,但我无法理解为什么即使没有变量的 cout 的第一行也不会出现。这只是战斗结束后的代码部分。 points 和standing 都是 int, int 映射。
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;
【问题讨论】: