我正在尝试为数学问题生成随机数。编译程序时,错误运算符“+”不能应用于“System.Random”和“System.Random”类型的操作数。我真的不知道如何解决这个错误。
Random num1 = new Random(0);
Random num2 =new Random(0);
int rand;
Console.Write("What is");
Console.Write(num1);
Console.Write( " - ");
Console.Write( num2);
Console.Write( "?");
int answer = Console.Read();
if (num1 + num2 == answer) ERROR {
Console.Write(" Your are Correct!\n");
correctCount++;
}
else
Console.Write( "Your answer is wrong" );
Console.Write(num1);
Console.Write(" + ");
Console.Write(num2);
Console.Write("should be ");
Console.Write(num1 + num2); ERROR
count++;
}
}
}
}
现在我能够编译程序而没有任何错误,但它没有生成任何数字。有谁看到我可能错了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Jagtutor
{
[Activity(Label = "Addition")]
public class AdditionsActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
SetContentView(Resource.Layout.Second);
var label = FindViewById<TextView>(Resource.Id.screen3Label);
label.Text = Intent.GetStringExtra("ModuleData") ?? "Data not available";
{
int correctCount = 0;
int count = 0;
while (count < 10);
{
Random gen = new Random();
int num1 = gen.Next();
int num2 = gen.Next();
Console.Write("What is");
Console.Write(num1);
Console.Write( " - ");
Console.Write( num2);
Console.Write( "?");
int answer = Int32.Parse(Console.ReadLine());
if (num1 + num2 == answer) {
Console.Write(" Your are Correct!\n");
correctCount++;
}
else
Console.Write( "Your answer is wrong" );
Console.Write(num1);
Console.Write(" + ");
Console.Write(num2);
Console.Write("should be ");
Console.Write(num1 + num2);
count++;
}
}
}
}
}