这个IF语句有什么问题吗? (C ++) [英] Is there anything wrong with this IF statement? (C++)
问题描述
这个IF语句本身有什么问题吗?因为它目前是真的所有的时间,所以我在漫游,如果我有我的语法错误的地方,它把它抛出来了?
Is there anything wrong with this IF statement in itself? Because it's currently true all the time and so I'm wandering if I've got my syntax wrong somewhere and it's throwing it out?
if (questinfo.targetitem == "coins" && questinfo.targetitemquant >= coins)
{
cout << "You have enough coins to complete your task!" << endl;
questactive = false;
}
questinfo.targetitem
是字符串
(不是字符数组)。
questinfo.targetitemquant
是 int 。
questactive
是 bool
。
coins
是一个 int
。
questinfo.targetitem
is a string
(not array of chars).
questinfo.targetitemquant
is an int
.
questactive
is a bool
.
coins
is an int
.
targetitemquant
目前不能大于 coins
但是语句总是完成为真。
targetitemquant
is NEVER greater than coins
at the moment but the statement always completes to true. Please tell me I've got my syntax wrong otherwise this just got far more difficult to pin down :(. Thanks.
推荐答案
请告诉我错误的语法错误,如果语法错误,编译器会产生一个错误,这样你就知道了。
If the syntax is wrong the compiler will produce an error, so that way you will know anyway.
如果编译但没有按预期工作,一个逻辑错误,在这种情况下你可以使用调试器来解决为什么。
If it is compiling but not working as you expect then it's going to be a logic error, in which case you can use a debugger to work out why.
它似乎不是一个语法错误,所以我建议调试它。
It doesn't seem to be a syntax error, so I would suggest debugging it.
这篇关于这个IF语句有什么问题吗? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!