tuzikyy
2015-11-20 12:59
采纳率: 50%
浏览 1.4k

c#入门级问题求大手子解决

Random r = new Random();
int d1 = r.Next( 1, 7 );
int d2 = r.Next( 1, 7 );
int sum = d1 + d2;
Console.WriteLine("Player rolled {0} + {1} = {2}",d1, d2, sum);
switch (sum)
{
case 11:
Console.WriteLine("player win");
break;
case 7:
Console.WriteLine("player win");
break;
case 2:
Console.WriteLine("player lose");
break;
case 3:
Console.WriteLine("player lose");
break;
case 12:
Console.WriteLine("player lose");
break;
default :
Console.WriteLine("Point is {0}", sum);
break;
}
if (sum != 11||sum != 12||sum !=7||sum != 2||sum !=3)
{
int q1 = r.Next(1, 7);
int q2 = r.Next(1, 7);
int o = q1 + q2;
Console.WriteLine("Player rolled {0} + {1} = {2}", q1, q2, o);
if (o == sum)
{
Console.WriteLine("player win");
}
while (o != sum)
{
int y1 = r.Next(1, 7);
int y2 = r.Next(1, 7);
int s = y1 + y2;
Console.WriteLine("Player rolled {0} + {1} = {2}", y1, y2, s);
o = s;
if (s == sum)
{
Console.WriteLine("player win");
break;
}
else if (s == 7)
{
Console.WriteLine("player lose");
break;
}
}
}
Random r = new Random();
int d1 = r.Next( 1, 7 );
int d2 = r.Next( 1, 7 );
int sum = d1 + d2;
Console.WriteLine("Player rolled {0} + {1} = {2}",d1, d2, sum);
switch (sum)
{
case 11:
Console.WriteLine("player win");
break;
case 7:
Console.WriteLine("player win");
break;
case 2:
Console.WriteLine("player lose");
break;
case 3:
Console.WriteLine("player lose");
break;
case 12:
Console.WriteLine("player lose");
break;
default :
Console.WriteLine("Point is {0}", sum);
break;
}
if (sum != 11||sum != 12||sum !=7||sum != 2||sum !=3)
{
int q1 = r.Next(1, 7);
int q2 = r.Next(1, 7);
int o = q1 + q2;
Console.WriteLine("Player rolled {0} + {1} = {2}", q1, q2, o);
if (o == sum)
{
Console.WriteLine("player win");
}
while (o != sum)
{
int y1 = r.Next(1, 7);
int y2 = r.Next(1, 7);
int s = y1 + y2;
Console.WriteLine("Player rolled {0} + {1} = {2}", y1, y2, s);
o = s;
if (s == sum)
{
Console.WriteLine("player win");
break;
}
else if (s == 7)
{
Console.WriteLine("player lose");
break;
}
}
}
Random r = new Random();
int d1 = r.Next( 1, 7 );
int d2 = r.Next( 1, 7 );
int sum = d1 + d2;
Console.WriteLine("Player rolled {0} + {1} = {2}",d1, d2, sum);
switch (sum)
{
case 11:
Console.WriteLine("player win");
break;
case 7:
Console.WriteLine("player win");
break;
case 2:
Console.WriteLine("player lose");
break;
case 3:
Console.WriteLine("player lose");
break;
case 12:
Console.WriteLine("player lose");
break;
default :
Console.WriteLine("Point is {0}", sum);
break;
}
if (sum != 11||sum != 12||sum !=7||sum != 2||sum !=3)
{
int q1 = r.Next(1, 7);
int q2 = r.Next(1, 7);
int o = q1 + q2;
Console.WriteLine("Player rolled {0} + {1} = {2}", q1, q2, o);
if (o == sum)
{
Console.WriteLine("player win");
}
while (o != sum)
{
int y1 = r.Next(1, 7);
int y2 = r.Next(1, 7);
int s = y1 + y2;
Console.WriteLine("Player rolled {0} + {1} = {2}", y1, y2, s);
o = s;
if (s == sum)
{
Console.WriteLine("player win");
break;
}
else if (s == 7)
{
Console.WriteLine("player lose");
break;
}
}
}
一个扔骰子问题,先扔两次,和为7或11,玩家赢,为2,3或12为玩家输,若为其他数,则这个数为“点数”,继续扔,一直扔到和为点数,玩家赢。但若和为7时,玩家输。
问题是if (sum != 11||sum != 12||sum !=7||sum != 2||sum !=3)没有起作用,不管第一次扔赢还是输,总会扔第二次。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • Revolution_lxx 2015-11-20 13:07
    已采纳

    if (sum != 11||sum != 12||sum !=7||sum != 2||sum !=3)

    =====================>>>>>>>>>>>>

    if (sum != 11 && sum != 12 && sum !=7 && sum != 2 && sum !=3)

    大兄弟 你短路了。。。

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题