【问题标题】:c++ program pausing in middle with console in entry modec++程序在入口模式下在控制台中间暂停
【发布时间】: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;

【问题讨论】:

    标签: c++11 map


    【解决方案1】:

    for (int j=1; j&lt;7;i++) 是一个无限循环——你可能指的是j++ 最后。因此,cout 行永远不会被执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 2022-08-21
      • 2018-09-29
      相关资源
      最近更新 更多