タイトルが言っていることとほぼ同じです。私はこの宝くじ番号の割り当ての最後の部分にいますが、デバッグ時にif /elseifステートメントの2番目のセットが表示されない理由がわかりません。if / elseステートメントは相互に排他的であることを知っていますが、両方のテストでifとthenを実行するべきではありませんか?これがコードです。
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++;
}
簡単にするために、whileループをforループに置き換えるべきだったと思いますが、whileループの方が快適です。