我对C#很新,并试图使文本基础mastermind,但当我尝试检查用户的答案是否与3个数字相同时,我得到此错误."运算符"||"不能应用于'bool'和'int'类型的操作数"
Random rnd = new Random();
int pos1 = rnd.Next(1, 6); //generates random numbers
int pos2 = rnd.Next(1, 6);
int pos3 = rnd.Next(1, 6);
int pos4 = rnd.Next(1, 6);
int answer1 = Convert.ToInt32(Console.ReadLine());
if (asnwer1 == pos1) //checks if answer is the same as pos1
{
Console.WriteLine("Right");
}
else if (answer1 == pos2 || pos3 || pos4)
{
Console.WriteLine("Wrong");
}
else {
Console.WriteLine("Nope");
Run Code Online (Sandbox Code Playgroud) Console.WriteLine("What is the first number?");
var svar_regneart01 = Console.ReadLine();
Console.WriteLine("What would you like to add to {0}?", svar_regneart01);
var svar_regneart02 = Console.ReadLine();
Console.WriteLine("The answer is " + (svar_regneart01 + svar_regneart02));
Run Code Online (Sandbox Code Playgroud)
我试图将两个变量加在一起,但它们只是彼此相邻打印出来.我使用var关键字的原因是因为我希望正在玩的人能够使用整数或浮点数.
c# ×2