幾乎標題所說的內容。我到了這個彩票號碼分配的最後一位,我不確定爲什麼第二組if/if語句在調試時不顯示。我知道if/else語句是相互排斥的 - 但是如果兩者都測試,不應該是if和then呢? 這是代碼。If/else如果不執行,即使在while循環內出現條件
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循環,但爲了簡單起見,我更加舒服。
你是否在調試器中逐行執行代碼? – 2013-03-24 17:04:40