CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Loops

  1. #1
    Join Date
    May 2001
    Location
    Central USA
    Posts
    7

    Loops

    I wrote this program for a project, thought it was working but it ends up doin what its suppose to once and then when u try to click an operation again it skips my Do..While loop.. why, what do i do to fix it??!?! Help!!! Fast!!!!

    Here's ONE section of the code...

    'Set Do..Whille loop to enter values to add together and enter "999" to stop the inputbox.
    Do While result <> 999
    result = InputBox("Enter the values <999 to stop>")
    If result <> 999 Then
    x = x + result
    End If
    Loop
    'Ask the user to enter the answer they think it is
    response = InputBox("What do you think the answer is?", "Answer")
    'Display a sad face if their answer is wrong or a happy face if the answer is correct
    If response = x Then
    frmHappy.Visible = True
    response = MsgBox("Congratulations! You got it right!", vbExclamation, "Happy")
    Else
    frmSad.Visible = True
    response = MsgBox("No, I'm sorry.. You should try again, or would you like to see the right answer?", vbYesNo, "Sad")
    If response = vbYes Then
    MsgBox ("The correct answer is " & x)
    ElseIf response = vbNo Then
    frmSad.Show
    End If
    End If



    Smile - somewhere its helping someone.

  2. #2
    Join Date
    May 2001
    Location
    Central USA
    Posts
    7

    Re: Loops

    nm - i just went back and made my global variables local and it works...

    now i just have another prob...
    i dont know exactly how to do tell it to subract and divide.
    i got add and multiply good to go but when i try to put more than 2 values in subtract and/or divide it doesnt get the answers it should... how do i fix it?

    Smile - somewhere its helping someone.

  3. #3
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Loops

    It will skip your do while loop because, as you said, was a global variable and still retained the value of '999' (your number to stop the process) the next time you need to use it. As far as fixing your calculation problems, post your code what you have already.


    David Paulson

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: Loops

    Not sure if this is what you're looking for:

    If you're operating on the previous value:
    substract:
    x = result - x

    divide:
    x = result / x

    -Cool Bizs

    Good Luck,
    -Cool Bizs

  5. #5
    Join Date
    May 2001
    Posts
    5

    Re: Loops

    divide:
    x=x/result


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

Featured