作业帮 > 综合 > 作业

怎样在vb中使计算机随机给出两位数加减法算术题,并随时给出真确率

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/06 06:20:11
怎样在vb中使计算机随机给出两位数加减法算术题,并随时给出真确率
怎样在vb中使计算机随机给出两位数加减法算术题,并随时给出真确率
定义三个变量,比如:
int a[],w,jieguo;
//数组a的值是0-100的整数,w的值是加法还是减法,jieguo是最后的运算结果.
a[0]=(int)(Math.random()*100);
a[1]=(int)(Math.random()*100);
w=(string)(random("+","-"));
if w="+"
{jieguo=a[0]+a[1];
label1.text=(string)(a[0])+"+"+(string)(a[1])+"="+(string)(jieguo)
}
else
{jieguo=a[0]-a[1];
label1.text=(string)(a[0])+"-"+(string)(a[1])+"="+(string)(jieguo)
}
end if
方法很笨…………- -!
再问: 还有正确率呢???
再答: 为了回答这个题,我专门做了个程序试了的,是可以的,你自己看看,这个绝对可以运行,不行找我382727978 声明中写: Dim a, b, c, yunsuan As Integer Dim rand As New Random() Dim cishu, zhengquegeshu As Integer 页面加载过程写: a = CInt(rand.Next(100)) b = CInt(rand.Next(100)) yunsuan = CInt(rand.Next(1)) diyige.Text = CStr(a) dierge.Text = CStr(b) If yunsuan = 0 Then yunsuanfu.Text = "+" Else yunsuanfu.Text = "-" End If 按钮事件里写: If yunsuan = 0 Then c = a + b Else c = a - b End If If c = Convert.ToString(TextBox1.Text) Then cishu = Val(Session("cishu")) + 1 Session("cishu") = cishu zhengquegeshu = Val(Session("zhengquegeshu")) + 1 Session("zhengquegeshu") = zhengquegeshu Else cishu = Val(Session("cishu")) + 1 Session("cishu") = cishu zhengquegeshu = Val(Session("zhengquegeshu")) Session("zhengquegeshu") = zhengquegeshu End If dijiti.Text = Session("cishu") zuodui.Text = Session("zhengquegeshu") jieguo.Text = CStr(c) zhengquelv.Text = CInt(Session("zhengquegeshu") )/Cint( Session("cishu")).ToString & "%" 或者不用百分比,直接用次数表示,比如做了8题,做对2题,正确率就显示为“2/8”,那最后一句就改成: zhengquelv.Text = "& Session("zhengquegeshu") &" &“/” & "& Session("cishu") &" 这段代码比较繁琐点,但是浅显易懂,都是我试过的,没啥问题