C#的类————应用
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication28
{
public class Chengfa
{
int x=0;
int X=0;
private int a;
private int b;
public int A
{
get { return a; }
set { a = value; }
}
public int B
{
get { return b; }
set { b = value; }
}
public void timu()
{
Random r = new Random();
a = r.Next(0, 10);
b = r.Next(0, 10);
Console.WriteLine(a+"和"+b+"的乘积是多少?" );
}
public void zhengque()
{
int c = int.Parse(Console.ReadLine());
for (int i = 0; i < 99; i++)
{
X++;
if (a * b == c)
{
Console.WriteLine("非常棒");
break;
}
else
{
Console.WriteLine(a + "和" + b + "的乘积是多少?");
this.zhengque();
break;
}
}
if (X == 1)
{
x=x+1;
}
}
public void zhengquelv()
{
float l = x / 10f;
if (l < 0.75)
{
Console.WriteLine("正确率为{0},请你的老师给你辅导一下",l);
}
else
{
Console.WriteLine("正确率为{0}", l);
}
}
}
class Program
{
static void Main(string[] args)
{
Chengfa chengfa = new Chengfa();
for (int n = 0; n < 10; n++)
{
chengfa.timu();
chengfa.zhengque();
}
chengfa.zhengquelv();
Console.ReadKey();
}
}
}
以上是我的作业
问题是x在自增时数据丢失,这个怎么修改