我的代码什么都没有。
问题描述:
请帮助我的代码直接进入按任意键继续......然后关闭。我是一个相当新的编码,所以原谅我的stupedness,无论如何是的,我尝试添加返回0;无处不在,它仍然无法正常工作。请帮助!!!
Please help my code goes straight to "Press any key to continue..." then it closes. I am fairly new to coding so excuse my stupedness, anyways yeah I tried adding return 0; everywhere and it still just doesn't work. PLEASE HELP!!!
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
using namespace std;
int rouletteGen();
int main()
{
//--------
//| Idea |
//--------
//cout << box 1 << box 2 << endl;
int wheel, a, b, c, time, cA, cB, cC;
a = 0;
b = 0;
c = 0;
time = 500;
while (a > 1)
{
cC = rouletteGen();
if (cC >= 0 && cC <= 15)
{
cC = 1;
}
else if (cC >= 16 && cC <= 30)
{
cC = 2;
}
else if (cC == 31)
{
cC = 0;
}
cout << " _l_" << endl;
cout << " \l/" << endl;
cout << "_______ _______ _______" << endl;
cout << "I I I I I I" << endl;
cout << "I "<< " " <<" I I "<< " " <<" I I "<< cC<<" I" << endl;
cout << "I I I I I I" << endl;
cout << "_______ _______ _______" << endl;
Sleep(250);
c++;
while (b > 1)
{
cB = cC;
cC = rouletteGen();
if (cC >= 0 && cC <= 15)
{
cC = 1;
}
else if (cC >= 16 && cC <= 30)
{
cC = 2;
}
else if (cC == 31)
{
cC = 0;
}
cout << " _l_" << endl;
cout << " \l/" << endl;
cout << "_______ _______ _______" << endl;
cout << "I I I I I I" << endl;
cout << "I " << " " << " I I " << cB << " I I " << cC << " I" << endl;
cout << "I I I I I I" << endl;
cout << "_______ _______ _______" << endl;
cin.get();
c++;
Sleep(250);
while (c >= 15)
{
cA = cB;
cB = cC;
cC = rouletteGen();
if (cC >= 0 && cC <= 15)
{
cC = 1;
}
else if (cC >= 16 && cC <= 30)
{
cC = 2;
}
else if (cC == 31)
{
cC = 0;
}
cout << " _l_" << endl;cout << " \l/" << endl;
cout << "_______ _______ _______" << endl;
cout << "I I I I I I" << endl;
cout << "I " << cA << " I I " << cB << " I I " << cC << " I" << endl;
cout << "I I I I I I" << endl;
cout << "_______ _______ _______" << endl;
Sleep(time);
time += 100;
return 0;
}
return 0;
}
return 0;
}
return 0;
}
int rouletteGen()
{
int dice;
srand(time(NULL));
dice = rand() % 31;
dice = dice + 1;
return dice;
}
答
a = 0;
while (a > 1)
在while循环中,a为0,因此永远不会是> 0所以你的循环永远不会执行,它向右返回0.
At the point of the while loop a is 0, so will never be > 0 so your loop never executes and it goes right to return 0.
你有一个而(a> 1)
评估从一开始就false
,因为你在开头设置了a = 0;
。
You have awhile (a > 1)
which evaluates tofalse
right from the start because you seta = 0;
at the beginning.