#include <iostream>
using namespace std;
int generateRandBone(){
int Bone = 0; // какого чёрта на второе срабатывание оно не обнуляет?
while (true) {
Bone = rand() % 6;
if (Bone != 0) {
break;
return Bone;
}
}
}
int oneBone, twoBone;
int main()
{
setlocale(LC_CTYPE, "");
cout << "Кто первый ходит?\n";
cout << "1) Человек\n";
cout << "2) Бот\n";
cout << "3) Рандом\n";
int userInput;
cin >> userInput;
if (userInput == 1) {
while (true)
{
oneBone = generateRandBone(); // пытался делить прям во функции, но а второй раз не делилось
twoBone = generateRandBone();
cout << "Вы потрясли кости в руке, хотите потрясти ещё или бросить?";
cout << "1) Потрясти ещё";
cout << "2) Бросить";
cin >> userInput;
if (userInput == 1)
{
;
}
else {
break;
}
}
cout << oneBone;
switch (oneBone)
{
case 1:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "| * |" << endl;
cout << "| |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
case 2:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| * |" << endl;
cout << "| |" << endl;
cout << "| * |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
case 3:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| * |" << endl;
cout << "| * |" << endl;
cout << "| * |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
case 4:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| * * |" << endl;
cout << "| |" << endl;
cout << "| * * |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
case 5:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| * * |" << endl;
cout << "| * |" << endl;
cout << "| * * |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
case 6:
cout << "===========" << endl;
cout << "| |" << endl;
cout << "| * * |" << endl;
cout << "| * * |" << endl;
cout << "| * * |" << endl;
cout << "| |" << endl;
cout << "===========" << endl;
break;
}
}
}
为什么第二代函数不能被6整除?
它伤害了我的眼睛!break 在这里显然是多余的!一般来说,如果你需要一个从 1 到 6 的随机数(据你所知),那么你就会被一个循环堆积起来。这要容易得多:
让我们继续...
或者,再次以更简单的方式:
但是像这样重建循环会更正确: