std::cout << "How many turns do you want to do?" << std::endl << std::endl << std::endl;
std::string turnsDefined;
std::cin >> turnsDefined;
//std::cin.sync();
bool hasPassed = false;
int objectSizeIniti = 0;
int objectSizePost = 0;
for(char c : turnsDefined){
objectSizeIniti++;
}
bool boolForCharIsDigi[objectSizeIniti];
for(bool _b : boolForCharIsDigi){
_b = false;
}
while(hasPassed != true){
for(char c : turnsDefined){
if(isdigit(c) == 0){
boolForCharIsDigi[objectSizePost] = false;
}else if (isdigit(c) != 0){
boolForCharIsDigi[objectSizePost] = true;
}
bool allTrue = false;
for(int i = 0; i < sizeof(boolForCharIsDigi)/sizeof(boolForCharIsDigi[0]); i++){
if(boolForCharIsDigi[i] == false){
allTrue = false;
std::cin >> turnsDefined;
std::cout << "You may only use numbers to define the amount of turns. No decimals either." << std::endl << std::endl;
break;
}else if(boolForCharIsDigi[i] == true){
allTrue = true;
hasPassed = true
}
}
}
objectSizePost++;
}
我想理解为什么上面的代码行为如此奇怪。奇怪的循环逻辑在c + +
我想要做的事:
,我发现了输入和测试,如果它仅由数字组成。如果是这样,它只是通过循环(将w循环检查的变量设置为true)。如果输入确实包含数字以外的字符,它会请求另一个输入并警告用户。
发生了什么:它随机需要一些输入来实际接受“唯一数字”。整体而言,整个项目只是随机行动。
你尝试调试它以检查问题?如果您尝试逐步调试,则可以轻松找到问题的原因。 – Jepessen 2014-10-27 17:18:32
'while(hasPassed!= true)'让我变得很温顺。 – 2014-10-27 17:22:51
@Jepessen这就是我所做的。没有帮助,虽然我根本无法弄清楚逻辑。它迭代真的很奇怪... – Code0 2014-10-27 17:26:40