两个随机数可除 [英] Two Random numbers Divisable

查看:80
本文介绍了两个随机数可除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我现在要说的是,我只是想看看这个程序以需要发布代码的方式运行,我没有要求任何人为我编写它,而是给我一些信息,只是让我知道如何我的代码看起来很糟糕,我确定我有几种不好的做法,因此,您可以提供给我的任何信息都很棒.目前只有两件事是行不通的,而且正在除法中,数字无法计算为可整除的

OK guys I am to the point now I would just like to see this program run the way it need to gonna post the code I have not asking anybody to write it for me but give me some information and just let me know how bad my code looks I''m sure that I have several bad practices and such going on any info you can give me will be great. there is just a couple of thing that isn''t work at the moment and that is in division the numbers are not working out to be evenly divisible

Public Class Slection
    Inherits System.Windows.Forms.Form
    Private Sub gui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        max_top.Hide()
        max_btm.Hide()
        lblDirections.Hide()
        Label1.Hide()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Gui.Show()
        Gui.Timer1.Enabled = True
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DDL.SelectedIndexChanged
        subject = DDL.SelectedIndex
        If check = 0 Then lblDirections.Show()
        max_top.Show()

        If check = 1 Then lblDirections.Show()
        max_top.Show()
        If check = 2 Then lblDirections.Show()
        max_top.Show()

        If check = 3 Then lblDirections.Show()
        max_top.Show()
        Label1.Show()
        max_btm.Show()

    End Sub
    Private Sub max_top_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles max_top.ValueChanged
        randnumtop = max_top.Value
    End Sub
    Private Sub max_btm_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles max_btm.ValueChanged
        randnum = max_btm.Value
    End Sub
    Public Sub time_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles time.ValueChanged
        myTime = (time.Value) * 60
    End Sub
End Class





Public Class Gui
    Inherits System.Windows.Forms.Form
    Public Sub Getnew()
        usranswer.Text = ""
        usranswer.Focus()
        If Correct > 0 Then RightLabel.Show()
        If countTotal > 0 Then TotalLabel.Show()
        If Missed > 0 Then Missedlabel.Show()
        RightLabel.Text = Correct & "Correct"
        Missedlabel.Text = Missed & "Missed"
        TotalLabel.Text = countTotal & "Total"
    End Sub
    Private Sub gui_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initilize*********************************************
        FormBorderStyle = FormBorderStyle.FixedSingle
        Timer1.Enabled = True
        check = subject
        Slection.Hide()
        RightLabel.Hide()
        TotalLabel.Hide()
        Missedlabel.Hide()
        RightLabel.BackColor = Color.Transparent
        TotalLabel.BackColor = Color.Transparent
        Missedlabel.BackColor = Color.Transparent
        Select Case check
            Case "0"
                Me.signbox.Image = Image.FromFile("C:\value\add.png")
            Case "1"
                Me.signbox.Image = Image.FromFile("C:\value\sub.gif")
            Case "2"
                Me.signbox.Image = Image.FromFile("C:\value\mul.gif")
            Case "3"
                Me.signbox.Image = Image.FromFile("C:\value\div.gif")
        End Select
        'Count of Questions Total
        countTotal = 0
        'Count of Correct Answers
        Correct = 0
        'count of Wrong Answers
        Missed = 0
        'Start Problems
        If subject = 3 Then Call dproblem() Else 
        Call problem()
        Call Getnew()
    End Sub
    '**************************************************************
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Select Case check
            Case "0"
                Call CheckAnswer_Add()
            Case "1"
                Call CheckAnswer_subtract()
            Case "2"
                Call CheckAnswer_Multiply()
            Case "3"
                Call CheckAnswer_Divide()
        End Select
        countTotal = Int(countTotal) + 1

    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
        Me.Close()
    End Sub
    '***********************************************Timer & Progress Bar************************************************************************
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Timer1.Interval = 1000
        myTime = myTime - 1
        TTLtxt.Text = myTime
        If myTime < 1 Then
            Timer1.Enabled = False
            MsgBox("Times Up!")
            MsgBox("Your score is :  " & (CInt(score) - CInt(points) & "%"))
            TTLtxt.Hide()
            My.Computer.FileSystem.WriteAllText("c:\value\value1.txt", "your Score is:" & score, False)
            Me.Close()
            Slection.Show()
        Else
        End If
        ProgressBar1.Maximum = (Slection.time.Value) * 59
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Enabled = False
        Else
            ProgressBar1.Value = ProgressBar1.Value + 1
        End If
            End Sub
End Class


Module variables
    '*********************Delclrations**************************************************************
    Public answer, reply, countTotal, randnum, randnumtop, num1, num2, Correct, Missed, score, points, myTime As Integer
    Public RandomClass1 As New Random()
    Public check, subject, div As String
    '***********************************************************************************************
    '***********************!!!!!!!!!Formulas!!!!!!!!!*********************************************
    Public Sub CheckAnswer_Multiply()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 * num2)
    End Sub
    Public Sub CheckAnswer_Add()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 + num2)
    End Sub
    Public Sub CheckAnswer_subtract()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 - num2)
    End Sub
    Public Sub CheckAnswer_Divide()
        Integer.TryParse(Gui.TopNumLabel.Text, num1)
        Integer.TryParse(Gui.ConstantLabel.Text, num2)
        Integer.TryParse(Gui.usranswer.Text, reply)
        answer = CInt(num1 / num2)

    End Sub
    '********************************CHECKS***************************************************************
    Public Sub UC()
        If answer = reply Then Correct = Int(Correct) + 1
        If Int(answer) <> Int(reply) Then Missed = Int(Missed) + 1
        If Int(answer) <> Int(reply) Then MsgBox(CStr(answer), MsgBoxStyle.Information, Title:=("Wrong"))
        points = ((100 / CInt(countTotal)) * CInt(Missed))
        score = 100
        If countTotal = 100 Then MsgBox("Great work you have completed 100 questions")
    End Sub
    Public Sub dproblem()
        Dim dnum1 As Integer
        Dim dnum2 As Integer = RandomClass1.Next(1, randnumtop)
        Dim danswer As Integer = RandomClass1.Next(1, 10)
        dnum1 = dnum2 * answer
        Gui.TopNumLabel.Text = dnum1
        Gui.ConstantLabel.Text = dnum2
    End Sub
    Public Sub problem()
        'Get Random Numbers for Problem
        Gui.TopNumLabel.Text = RandomClass1.Next(randnumtop)
        Gui.ConstantLabel.Text = RandomClass1.Next(randnum)
        'Make sure top number bigger than bottom
        If Integer.Parse(Gui.TopNumLabel.Text) < Integer.Parse(Gui.ConstantLabel.Text) Then
            Call problem()
        Else
        End If
    End Sub
    Public Function GetRandom(ByVal Min As Integer, ByVal Max As Integer) As Integer
        ' by making Generator static, we preserve the same instance '
        ' (i.e., do not create new instances with the same seed over and over) '
        ' between calls '
        Static RandomClass1 As System.Random = New System.Random()
        Return RandomClass1.Next(randnumtop, randnum)
    End Function
End Module

推荐答案

您正在向后看问题.如果您想要一个均匀可分的问题,请从答案开始,然后倒推.在"X/Y = Z"的问题中,选择一个随机答案值(Z)并将其乘以除数(Y)得到X.结果是一个非常整齐的可等式.
You''re looking at the problem backwards. If you want an evenly divisble problem, start with the answer and work backwards. In a problem of "X / Y = Z" Pick a random answer value (Z) and multiply it by your divisor (Y) to get X. The result is a very neatly divisible equation.


0)我要告诉你,在VB.Net中完全不需要使用Call关键字.

1)我看不到您发布的代码在您的mod代码中的位置.

2)我在您的代码中看不到任何循环.
0) I gotta tell you that using the Call keyword is completely unnecessary in VB.Net.

1) I don''t see where you mod code is in the code you posted.

2) I don''t see any loops in your code.


这篇关于两个随机数可除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆