Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用数组条件中断循环_C++_Arrays_Loops_For Loop_If Statement - Fatal编程技术网

C++ 使用数组条件中断循环

C++ 使用数组条件中断循环,c++,arrays,loops,for-loop,if-statement,C++,Arrays,Loops,For Loop,If Statement,我目前正在为班级制作一个滑梯和梯子游戏。这场比赛的获胜条件是,如果一名球员降落在100号广场上,他们获胜。如果他们刚好超过100,他们会一直呆在那里直到每个人都完成游戏(要么有人在100上着陆,要么每个人都超过100)。如果每个人都超过100岁,我很难打破while循环 有很多代码,所以我会尽量简化。在下面问题就在这里!!!!这就是我需要帮助的地方 有没有一种方法可以指定一旦数组中的所有元素都超过100,就要断开?抱歉,如果问题是重复的…这篇文章有更多的细节 string name[MAXpla

我目前正在为班级制作一个滑梯和梯子游戏。这场比赛的获胜条件是,如果一名球员降落在100号广场上,他们获胜。如果他们刚好超过100,他们会一直呆在那里直到每个人都完成游戏(要么有人在100上着陆,要么每个人都超过100)。如果每个人都超过100岁,我很难打破while循环

有很多代码,所以我会尽量简化。在下面问题就在这里!!!!这就是我需要帮助的地方

有没有一种方法可以指定一旦数组中的所有元素都超过100,就要断开?抱歉,如果问题是重复的…这篇文章有更多的细节

string name[MAXplayers]; //Array to store names
int position[MAXplayers]; //Array to store board position

unsigned seed; //Random Number Generator Seed
seed = time(0); //Set seed to 0
srand(seed); //Call srand function

int spin;
bool done = false;
int counter = 0;
const int WIN = 100;

while (done != true)
{
    if (counter == WIN)
    {
        cout << "That's it, game over!" << endl << endl;
        done = true;
    }
    else 
    {
        for (int i = 0; i < players; i++)
        {
            if (position[i] > WIN) //!!!!!HERE IS THE PROBLEM!!!!!!
            {
                cout << "Sorry " << name[i] << "! You can't move! You're stuck at " << position[i] << endl << endl;
            }
            else
            {
                cout << name[i] << "'s turn! Pres [Enter] to spin the wheel!";
                cin.get();
                spin = rand() % 12 + 1;
                cout << "You spun the number " << spin << "!" << endl;

                int temploc = position[i] += spin;
etc...etc...etc...etc...etc...etc...
字符串名[MAXplayers]//用于存储名称的数组
int位置[MAXplayers]//存储电路板位置的阵列
无标记种子//随机数发生器种子
种子=时间(0)//将种子设置为0
srand(种子)//调用srand函数
int自旋;
bool done=false;
int计数器=0;
常数int WIN=100;
while(完成!=真)
{
如果(计数器==赢)
{

cout若要在满足赢的条件时中断inter
for
循环,可以使用关键字break。这将停止循环处理,无论
for
循环的条件如何


请注意,在中断后,程序仍将在你的
循环中迭代,直到满足条件
完成!=true

可能重复@1201programalam:的确-该问题应该被修改而不是重新提问。我关闭了原来的循环。如果我参与,最终会非常棒如果我能在while(所有玩家的位置>100)时执行此操作,uld将跳出while循环@G.Nguyen:您正在描述函数
while(std::ALL_of(…
),但我怀疑您实际上想继续玩,直到所有位置>100,或任何位置<100。