问题描述
一个扔骰子问题,先扔两次,和为7或11,玩家赢,为2,3或12为玩家输,若为其他数,则这个数为“点数”,继续扔,一直扔到和为点数,玩家赢。但若和为7时,玩家输。问题是if(sum!=11||sum!=12||sum!=7||sum!=2||sum!=3)没有起作用,不管第一次扔赢还是输,总会扔第二次。Randomr=newRandom();intd1=r.Next(1,7);intd2=r.Next(1,7);intsum=d1+d2;Console.WriteLine("Playerrolled{0}+{1}={2}",d1,d2,sum);switch(sum){case11:Console.WriteLine("playerwin");break;case7:Console.WriteLine("playerwin");break;case2:Console.WriteLine("playerlose");break;case3:Console.WriteLine("playerlose");break;case12:Console.WriteLine("playerlose");break;default:Console.WriteLine("Pointis{0}",sum);break;}if(sum!=11||sum!=12||sum!=7||sum!=2||sum!=3){intq1=r.Next(1,7);intq2=r.Next(1,7);into=q1+q2;Console.WriteLine("Playerrolled{0}+{1}={2}",q1,q2,o);if(o==sum){Console.WriteLine("playerwin");}while(o!=sum){inty1=r.Next(1,7);inty2=r.Next(1,7);ints=y1+y2;Console.WriteLine("Playerrolled{0}+{1}={2}",y1,y2,s);o=s;if(s==sum){Console.WriteLine("playerwin");break;}elseif(s==7){Console.WriteLine("playerlose");break;}}}
解决方案
解决方案二:
if(sum!=11&&sum!=12&&sum!=7&&sum!=2&&sum!=3)
解决方案三:
多谢多谢,刚学,脑子短路了
解决方案四:
&&和||没分清