Random Number Guessing Game
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Random Number Guessing Game

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    Random Number Guessing Game

    I don't understand where I am doing something wrong. The instructions is to create a random application that generates a random number in the range of 1 through 100. If it's too low state "too low, try again" and the same for if it's too high.

    (I'm using visual basic)

    So I declared my variables and wrote a code for the procedure. I declared x as my integer. Any advice on how to correct it?
    Thanks for all help

    intNum = rand.Next(100) + 1
    For
    For x > intNum
    MsgBox("Too high, try again")
    Next
    For x < intNum
    MsgBox("Too low, try again")
    Next
    For x = intNum
    MsgBox("You guessed right!")
    Next
    Next

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Random Number Guessing Game

    Welcome to the forums!

    What happens when you try to run it? Where does it STOP? That is where the first error is. If it doesn't get that far, then the compiler doesn't understand what you tried to do. (neither do it, from looking)

    Also, use CODE TAGS if you want to post code.

    Code:
    ' This is code
      Dim a As Integer, b as Integer
      Dim c as Integer, d as String
      a=5
      b=3
      c = a + b
      d = format("$.00, c)
      Print d  ' WHAT DOES IT PRINT HERE???
      end
    also, looks like you want the VB.Net forum. Random.Next(10) doesn't work in VB6
    Last edited by dglienna; November 24th, 2012 at 07:20 PM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Random Number Guessing Game

    [Moved to VB.NET forum]
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Random Number Guessing Game

    You are supposed to use a While loop instead of a For loop. With a While loop - which is a conditional loop - you can loop without knowing the exact amount of times it should repeat.

    Is this a Console application or Windows Forms?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center