gpt4 book ai didi

c++ - While/For 循环不会循环。 (C++)

转载 作者:太空宇宙 更新时间:2023-11-04 16:10:49 25 4
gpt4 key购买 nike

<分区>

我是编程新手。但由于我正在制作一个简单的老虎机(它还没有奖品),我似乎无法制作循环,让玩家再试一次!如果我将条件设置为 1,它会很好地循环,但不是我有一个简单的 ( i > 0 ) 条件。这是代码:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int slot1 (int low, int high)
{
return rand() % ( high - low + 2 ) + low;
}

int slot2 (int low, int high)
{
return rand() % ( high - low + 2 ) + low;
}

int slot3 (int low, int high)
{
return rand() % ( high - low + 2 ) + low;
}

int main()
{
int i = 100;
cout << "\n\n Welcome to the Slot Machine!\n\n";
cout << " You have " << i << " coins!\n\n";
cout << " Each spin costs 1 coin! Press ENTER to begin.\n\n";
"\n";

while ( i > 0 )
{
cin.get();
"\n";
--i;
srand( time( NULL ) );
cout << " | " << slot1( 1, 8);
cout << " | " << slot2( 1, 8);
cout << " | " << slot3( 1, 8) << " |\n";

// if statements adding to int i, depending of the values of slot1, slot2 and slot3.

if (i = 0 )
{
break;
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com