Results 1 to 3 of 3

Thread: Easiest Question Ever

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Easiest Question Ever

    The code below should print out the multiplication table from 1 to 9. The for loops are fine; however, the logic on the Do until loop is the part causing the problem. Supposedly it will exit the do until loop once (answer = (i*j)) returns true. But this does not happen. If I use <> instead of = it will increment the j count, but it does not care what I enter for answer. I am a little confused as to why this does not work the way I was thinking it did. Please let me knwo if you can help shed some light on this logic with me.

    I appreciate your time and help.

    Code:
    <script type="text/vbscript">
    Dim i 
    Dim j 
    Dim answer 
    
    For i = 1 to 9 Step 1
       For j = 0 to 9 Step 1
          Do
             answer = InputBox("Whats " & i & " * " &  j & "?")
          Loop Until(answer = i * j)
       Next
    Next
    </script>
    Thank you/þankung/Danke/Vjelpa ye

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Easiest Question Ever

    It's because you are comparing a number to a string. Change this line
    Loop Until(answer = i * j)
    to
    Loop Until(cint(answer) = i * j)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Easiest Question Ever

    I knew it was a type problem all along! Thanks for your help!!

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

Posting Permissions

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



Click Here to Expand Forum to Full Width