【发布时间】:2013-03-14 03:20:47
【问题描述】:
和标题说的差不多。我到了这个彩票号码分配的最后一点,我不确定为什么在调试时没有显示第二组 if/else if 语句。我知道 if/else 语句是互斥的 - 但不应该一个 if 和另一个 if 都测试吗? 这是代码。
count=0;
while(count<5)
{
if(lottery[count] == user[count])
{
lotto = lottery[count];
cout<<"So, you matched numbers with "<<lotto <<".\n";
tally++;
}
if(tally==5 && count == 5)
{
cout<<"Congratulations, you're the grand prize winner!";
}
else if(tally < 5 && count == 5)
{
cout<<"A total of "<<tally<<" of your lottery picks matched.";
}
else if(tally == 0 && count == 5)
{
cout<<"Caution. The following comment is an inside joke. Read at your own risk.";
cout<<"Bet you feel like a total loser huh? Nothing matched.";
}
count++;
}
我知道为了简单起见,我可能应该用 for 循环替换 while 循环,但我更喜欢 while。
【问题讨论】:
-
你有没有在调试器中逐行检查代码?
标签: c++ while-loop if-statement