1에서 100 사이 숫자 맞추기
*
Public Class Form1

Dim attempts1 As Integer = 0
Dim answer1 As Integer = 12

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim guess1 As Integer = TextBox1.Text

attempts1 = (attempts1 + 1)
Label2.Text = "시도횟수 : " & attempts1

If answer1 = guess1 Then
Label1.Text = "맞음"
ElseIf answer1 < guess1 Then
Label1.Text = guess1 & "보다 낮음"
ElseIf answer1 > guess1 Then
Label1.Text = guess1 & "보다 높음"
End If
End Sub
End Class

숫자 맞추기 입니다.

정답은 12로 고정되여있습니다.

랜덤한 답이 나오게 코드를 고쳐 보세여. 

 

숫자맞추기.png

 

이 게시물을

댓글'2'
V닉맨
  • 2014.10.15
  • 수정: 2014.10.15 07:31:39

4.png

 

Public Class Form1
    Dim n, n1, count As Integer
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Label2.Text = "0"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim rand As New Random

        n = rand.Next(1, 101)
        Randomize()
        MsgBox("숫자를 생성 했습니다" & vbCrLf & "이제 숫자를 맞춰보세요!!")

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        count += 1
        Label2.Text += 1
        n1 = TextBox1.Text

        Label1.Text = "시도횟수 : " & count & "번"

 

        If n = n1 Then
            MsgBox("정답입니다!! " & vbCrLf & count & " 번 만에 맞추셨네요!!")
            TextBox2.Text += count & "번만에 맞춤" & vbCrLf
            TextBox1.Text = ""
            count = 0
            Label2.Text = "0"

        ElseIf n > n1 Then
            MsgBox(n1 & " 이(가) 정답보다 작습니다")
        ElseIf n < n1 Then
            MsgBox(n1 & " 이(가) 정답보다 큽니다")
        End If

       

    End Sub

    Private Sub TextBox1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick
        TextBox1.Text = ""
    End Sub

End Class

이 댓글을

교교
  • 2014.10.15

Public Class Form1
    Dim myVal As Integer
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = myVal Then
            Label3.Text = "  정답입니다 "
        ElseIf TextBox1.Text < myVal Then
            Label3.Text = "  작은 값입니다 "
        ElseIf TextBox1.Text > myVal Then
            Label3.Text = "  큰 값입니다 "
        Else
            Label3.Text = " 정확한 값을 입력하세요 "
        End If
        Label2.Text += 1

    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim myRand As New Random
        myVal = myRand.Next(1, 99)
        Randomize()
        'Label4.Text = myVal
    End Sub
End Class

이 댓글을

공유하기

SEARCH

MENU NAVIGATION