A simple example of C dealing with guessing game of non form
- 2021-10-27 08:40:48
- OfStack
C # Simple example of dealing with guessing game problem (non-form)
// Guess boxing, 5 Bureau 3 Win, requiring the use of common variables.
namespace Structural body review _ Common variable
{
class Program
{public int rz=0;
public int dz = 0;
public string bj(int a , int b)
{
int d = a - b;
if (d==-2||d==1)
{
return " People ";
}
else if (d==2||d==-1)
{
return " Computer ";
}
else
{
return " And ";
}
}
static void Main(string[] args)
{Random sj = new Random();
Program zdy=new Program();
while (zdy.rz < 3 && zdy.dz < 3)
{
Console.WriteLine(" Please enter the digital code of scissors stone cloth ( 1 For scissors, 2 For Stone, 3 For cloth): ");
int a = int.Parse(Console.ReadLine());
int b = sj.Next(1,4);
string jg = zdy.bj(a, b);
switch (jg)
{
case " People ":
zdy.rz++;
Console.WriteLine(" You win this Council ");
break;
case " Computer ":
zdy.dz++;
Console.WriteLine(" This Council computer wins ");
break;
case " And ":
Console.WriteLine(" A tie in this Council ");
break;
}
}
if (zdy.rz > zdy.dz)
{
Console.WriteLine(" You win ");
}
else
{
Console.WriteLine(" You lose ");
}
Console.ReadLine();
}
}
}