2 Replies - 241 Views - Last Post: 15 November 2012 - 08:19 PM Rate Topic: -----

#1 Anguishedsix50  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-November 12

How to fix a problem with Output of a Program

Posted 15 November 2012 - 05:20 PM

Hello. I am working on a final project for my introduction to computer programming class. I am working in VB.NET 2008.
I have tried to create a hangman game. I have replicated the code and have not had error messages. Once run the wrong box displays z even if the letter was correct (The correct letter also does not appear.I have tried fixing it yet only have made things worse. This is a snippet of the project. This is the input and the first guess check system. Any help would be greatly aprreciated.
  Label22.Text = wrongtotal
        Label24.Text = total 
        letter1 = InputBox("Enter the first letter.", "Hangman")
        letter2 = InputBox("Enter the second letter.", "Hangman")
        letter3 = InputBox("Enter the third letter.", "Hangman")
        letter4 = InputBox("Enter the fourth letter.", "Hangman")
        letter5 = InputBox("Enter the fifth letter.", "Hangman")
        letter6 = InputBox("Enter the sixth letter.", "Hangman")
        letter7 = InputBox("Enter the seventh letter.", "Hangman")
        letter8 = InputBox("Enter the eighth letter.", "Hangman")
        letter9 = InputBox("Enter the ninth letter.", "Hangman")
        letter10 = InputBox("Enter the tenth letter.", "Hangman")
        If letter1 = " " Then
            Label1.Visible = False
            Label2.Visible = False
        End If
        If letter2 = " " Then
            Label3.Visible = False
            Label4.Visible = False
        End If
        If letter3 = " " Then
            Label5.Visible = False
            Label6.Visible = False
        End If
        If letter4 = " " Then
            Label7.Visible = False
            Label8.Visible = False
        End If
        If letter5 = " " Then
            Label9.Visible = False
            Label10.Visible = False
        End If
        If letter6 = " " Then
            Label11.Visible = False
            Label12.Visible = False
        End If
        If letter7 = " " Then
            Label13.Visible = False
            Label14.Visible = False
        End If
        If letter8 = " " Then
            Label15.Visible = False
            Label16.Visible = False
        End If
        If letter9 = " " Then
            Label17.Visible = False
            Label18.Visible = False
        End If
        If letter10 = " " Then
            Label19.Visible = False
            Label20.Visible = False
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Guess1 = txtguess.Text
        total = total + 1
        If wrongtotal = 0 Then
            If Guess1 = letter1 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter2 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter3 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter4 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter5 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter6 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter7 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter8 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter9 Then
                wrong1.Text = "?"
            End If
            If Guess1 = letter10 Then
                wrong1.Text = "?"
            End If
            If Guess1 = "A" Then
                If letter1 = "A" Then Label2.Text = "A"
                If letter2 = "A" Then Label4.Text = "A"
                If letter3 = "A" Then Label6.Text = "A"
                If letter4 = "A" Then Label8.Text = "A"
                If letter5 = "A" Then Label10.Text = "A"
                If letter6 = "A" Then Label12.Text = "A"
                If letter7 = "A" Then Label14.Text = "A"
                If letter8 = "A" Then Label16.Text = "A"
                If letter9 = "A" Then Label18.Text = "A"
                If letter10 = "A" Then Label20.Text = "A"
            Else : wrong1.Text = "A"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "B" Then
                If letter1 = "B" Then Label2.Text = "B"
                If letter2 = "B" Then Label4.Text = "B"
                If letter3 = "B" Then Label6.Text = "B"
                If letter4 = "B" Then Label8.Text = "B"
                If letter5 = "B" Then Label10.Text = "B"
                If letter6 = "B" Then Label12.Text = "B"
                If letter7 = "B" Then Label14.Text = "B"
                If letter8 = "B" Then Label16.Text = "B"
                If letter9 = "B" Then Label18.Text = "B"
                If letter10 = "B" Then Label20.Text = "B"
            Else : wrong1.Text = "B"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "C" Then
                If letter1 = "C" Then Label2.Text = "C"
                If letter2 = "C" Then Label4.Text = "C"
                If letter3 = "C" Then Label6.Text = "C"
                If letter4 = "C" Then Label8.Text = "C"
                If letter5 = "C" Then Label10.Text = "C"
                If letter6 = "C" Then Label12.Text = "C"
                If letter7 = "C" Then Label14.Text = "C"
                If letter8 = "C" Then Label16.Text = "C"
                If letter9 = "C" Then Label18.Text = "C"
                If letter10 = "C" Then Label20.Text = "C"
            Else : wrong1.Text = "C"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "D" Then
                If letter1 = "D" Then Label2.Text = "D"
                If letter2 = "D" Then Label4.Text = "D"
                If letter3 = "D" Then Label6.Text = "D"
                If letter4 = "D" Then Label8.Text = "D"
                If letter5 = "D" Then Label10.Text = "D"
                If letter6 = "D" Then Label12.Text = "D"
                If letter7 = "D" Then Label14.Text = "D"
                If letter8 = "D" Then Label16.Text = "D"
                If letter9 = "D" Then Label18.Text = "D"
                If letter10 = "D" Then Label20.Text = "D"
            Else : wrong1.Text = "D"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "E" Then
                If letter1 = "E" Then Label2.Text = "E"
                If letter2 = "E" Then Label4.Text = "E"
                If letter3 = "E" Then Label6.Text = "E"
                If letter4 = "E" Then Label8.Text = "E"
                If letter5 = "E" Then Label10.Text = "E"
                If letter6 = "E" Then Label12.Text = "E"
                If letter7 = "E" Then Label14.Text = "E"
                If letter8 = "E" Then Label16.Text = "E"
                If letter9 = "E" Then Label18.Text = "E"
                If letter10 = "E" Then Label20.Text = "E"
            Else : wrong1.Text = "E"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "F" Then
                If letter1 = "F" Then Label2.Text = "F"
                If letter2 = "F" Then Label4.Text = "F"
                If letter3 = "F" Then Label6.Text = "F"
                If letter4 = "F" Then Label8.Text = "F"
                If letter5 = "F" Then Label10.Text = "F"
                If letter6 = "F" Then Label12.Text = "F"
                If letter7 = "F" Then Label14.Text = "F"
                If letter8 = "F" Then Label16.Text = "F"
                If letter9 = "F" Then Label18.Text = "F"
                If letter10 = "F" Then Label20.Text = "F"
            Else : wrong1.Text = "F"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "G" Then
                If letter1 = "G" Then Label2.Text = "G"
                If letter2 = "G" Then Label4.Text = "G"
                If letter3 = "G" Then Label6.Text = "G"
                If letter4 = "G" Then Label8.Text = "G"
                If letter5 = "G" Then Label10.Text = "G"
                If letter6 = "G" Then Label12.Text = "G"
                If letter7 = "G" Then Label14.Text = "G"
                If letter8 = "G" Then Label16.Text = "G"
                If letter9 = "G" Then Label18.Text = "G"
                If letter10 = "G" Then Label20.Text = "G"
            Else : wrong1.Text = "G"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "H" Then
                If letter1 = "H" Then Label2.Text = "H"
                If letter2 = "H" Then Label4.Text = "H"
                If letter3 = "H" Then Label6.Text = "H"
                If letter4 = "H" Then Label8.Text = "H"
                If letter5 = "H" Then Label10.Text = "H"
                If letter6 = "H" Then Label12.Text = "H"
                If letter7 = "H" Then Label14.Text = "H"
                If letter8 = "H" Then Label16.Text = "H"
                If letter9 = "H" Then Label18.Text = "H"
                If letter10 = "H" Then Label20.Text = "H"
            Else : wrong1.Text = "H"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "I" Then
                If letter1 = "I" Then Label2.Text = "I"
                If letter2 = "I" Then Label4.Text = "I"
                If letter3 = "I" Then Label6.Text = "I"
                If letter4 = "I" Then Label8.Text = "I"
                If letter5 = "I" Then Label10.Text = "I"
                If letter6 = "I" Then Label12.Text = "I"
                If letter7 = "I" Then Label14.Text = "I"
                If letter8 = "I" Then Label16.Text = "I"
                If letter9 = "I" Then Label18.Text = "I"
                If letter10 = "I" Then Label20.Text = "I"
            Else : wrong1.Text = "I"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "J" Then
                If letter1 = "J" Then Label2.Text = "J"
                If letter2 = "J" Then Label4.Text = "J"
                If letter3 = "J" Then Label6.Text = "J"
                If letter4 = "J" Then Label8.Text = "J"
                If letter5 = "J" Then Label10.Text = "J"
                If letter6 = "J" Then Label12.Text = "J"
                If letter7 = "J" Then Label14.Text = "J"
                If letter8 = "J" Then Label16.Text = "J"
                If letter9 = "J" Then Label18.Text = "J"
                If letter10 = "J" Then Label20.Text = "J"
            Else : wrong1.Text = "J"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "K" Then
                If letter1 = "K" Then Label2.Text = "K"
                If letter2 = "K" Then Label4.Text = "K"
                If letter3 = "K" Then Label6.Text = "K"
                If letter4 = "K" Then Label8.Text = "K"
                If letter5 = "K" Then Label10.Text = "K"
                If letter6 = "K" Then Label12.Text = "K"
                If letter7 = "K" Then Label14.Text = "K"
                If letter8 = "K" Then Label16.Text = "K"
                If letter9 = "K" Then Label18.Text = "K"
                If letter10 = "K" Then Label20.Text = "K"
            Else : wrong1.Text = "K"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "L" Then
                If letter1 = "L" Then Label2.Text = "L"
                If letter2 = "L" Then Label4.Text = "L"
                If letter3 = "L" Then Label6.Text = "L"
                If letter4 = "L" Then Label8.Text = "L"
                If letter5 = "L" Then Label10.Text = "L"
                If letter6 = "L" Then Label12.Text = "L"
                If letter7 = "L" Then Label14.Text = "L"
                If letter8 = "L" Then Label16.Text = "L"
                If letter9 = "L" Then Label18.Text = "L"
                If letter10 = "L" Then Label20.Text = "L"
            Else : wrong1.Text = "L"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "M" Then
                If letter1 = "M" Then Label2.Text = "M"
                If letter2 = "M" Then Label4.Text = "M"
                If letter3 = "M" Then Label6.Text = "M"
                If letter4 = "M" Then Label8.Text = "M"
                If letter5 = "M" Then Label10.Text = "M"
                If letter6 = "M" Then Label12.Text = "M"
                If letter7 = "M" Then Label14.Text = "M"
                If letter8 = "M" Then Label16.Text = "M"
                If letter9 = "M" Then Label18.Text = "M"
                If letter10 = "M" Then Label20.Text = "M"
            Else : wrong1.Text = "M"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "N" Then
                If letter1 = "N" Then Label2.Text = "N"
                If letter2 = "N" Then Label4.Text = "N"
                If letter3 = "N" Then Label6.Text = "N"
                If letter4 = "N" Then Label8.Text = "N"
                If letter5 = "N" Then Label10.Text = "N"
                If letter6 = "N" Then Label12.Text = "N"
                If letter7 = "N" Then Label14.Text = "N"
                If letter8 = "N" Then Label16.Text = "N"
                If letter9 = "N" Then Label18.Text = "N"
                If letter10 = "N" Then Label20.Text = "N"
            Else : wrong1.Text = "N"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "O" Then
                If letter1 = "O" Then Label2.Text = "O"
                If letter2 = "O" Then Label4.Text = "O"
                If letter3 = "O" Then Label6.Text = "O"
                If letter4 = "O" Then Label8.Text = "O"
                If letter5 = "O" Then Label10.Text = "O"
                If letter6 = "O" Then Label12.Text = "O"
                If letter7 = "O" Then Label14.Text = "O"
                If letter8 = "O" Then Label16.Text = "O"
                If letter9 = "O" Then Label18.Text = "O"
                If letter10 = "O" Then Label20.Text = "O"
            Else : wrong1.Text = "O"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "P" Then
                If letter1 = "P" Then Label2.Text = "P"
                If letter2 = "P" Then Label4.Text = "P"
                If letter3 = "P" Then Label6.Text = "P"
                If letter4 = "P" Then Label8.Text = "P"
                If letter5 = "P" Then Label10.Text = "P"
                If letter6 = "P" Then Label12.Text = "P"
                If letter7 = "P" Then Label14.Text = "P"
                If letter8 = "P" Then Label16.Text = "P"
                If letter9 = "P" Then Label18.Text = "P"
                If letter10 = "P" Then Label20.Text = "P"
            Else : wrong1.Text = "P"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "Q" Then
                If letter1 = "Q" Then Label2.Text = "Q"
                If letter2 = "Q" Then Label4.Text = "Q"
                If letter3 = "Q" Then Label6.Text = "Q"
                If letter4 = "Q" Then Label8.Text = "Q"
                If letter5 = "Q" Then Label10.Text = "Q"
                If letter6 = "Q" Then Label12.Text = "Q"
                If letter7 = "Q" Then Label14.Text = "Q"
                If letter8 = "Q" Then Label16.Text = "Q"
                If letter9 = "Q" Then Label18.Text = "Q"
                If letter10 = "Q" Then Label20.Text = "Q"
            Else : wrong1.Text = "Q"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "R" Then
                If letter1 = "R" Then Label2.Text = "R"
                If letter2 = "R" Then Label4.Text = "R"
                If letter3 = "R" Then Label6.Text = "R"
                If letter4 = "R" Then Label8.Text = "R"
                If letter5 = "R" Then Label10.Text = "R"
                If letter6 = "R" Then Label12.Text = "R"
                If letter7 = "R" Then Label14.Text = "R"
                If letter8 = "R" Then Label16.Text = "R"
                If letter9 = "R" Then Label18.Text = "R"
                If letter10 = "R" Then Label20.Text = "R"
            Else : wrong1.Text = "R"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "S" Then
                If letter1 = "S" Then Label2.Text = "S"
                If letter2 = "S" Then Label4.Text = "S"
                If letter3 = "S" Then Label6.Text = "S"
                If letter4 = "S" Then Label8.Text = "S"
                If letter5 = "S" Then Label10.Text = "S"
                If letter6 = "S" Then Label12.Text = "S"
                If letter7 = "S" Then Label14.Text = "S"
                If letter8 = "S" Then Label16.Text = "S"
                If letter9 = "S" Then Label18.Text = "S"
                If letter10 = "S" Then Label20.Text = "S"
            Else : wrong1.Text = "S"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "T" Then
                If letter1 = "T" Then Label2.Text = "T"
                If letter2 = "T" Then Label4.Text = "T"
                If letter3 = "T" Then Label6.Text = "T"
                If letter4 = "T" Then Label8.Text = "T"
                If letter5 = "T" Then Label10.Text = "T"
                If letter6 = "T" Then Label12.Text = "T"
                If letter7 = "T" Then Label14.Text = "T"
                If letter8 = "T" Then Label16.Text = "T"
                If letter9 = "T" Then Label18.Text = "T"
                If letter10 = "T" Then Label20.Text = "T"
            Else : wrong1.Text = "T"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "U" Then
                If letter1 = "U" Then Label2.Text = "U"
                If letter2 = "U" Then Label4.Text = "U"
                If letter3 = "U" Then Label6.Text = "U"
                If letter4 = "U" Then Label8.Text = "U"
                If letter5 = "U" Then Label10.Text = "U"
                If letter6 = "U" Then Label12.Text = "U"
                If letter7 = "U" Then Label14.Text = "U"
                If letter8 = "U" Then Label16.Text = "U"
                If letter9 = "U" Then Label18.Text = "U"
                If letter10 = "U" Then Label20.Text = "U"
            Else : wrong1.Text = "U"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "V" Then
                If letter1 = "V" Then Label2.Text = "V"
                If letter2 = "V" Then Label4.Text = "V"
                If letter3 = "V" Then Label6.Text = "V"
                If letter4 = "V" Then Label8.Text = "V"
                If letter5 = "V" Then Label10.Text = "V"
                If letter6 = "V" Then Label12.Text = "V"
                If letter7 = "V" Then Label14.Text = "V"
                If letter8 = "V" Then Label16.Text = "V"
                If letter9 = "V" Then Label18.Text = "V"
                If letter10 = "V" Then Label20.Text = "V"
            Else : wrong1.Text = "V"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "W" Then
                If letter1 = "W" Then Label2.Text = "W"
                If letter2 = "W" Then Label4.Text = "W"
                If letter3 = "W" Then Label6.Text = "W"
                If letter4 = "W" Then Label8.Text = "W"
                If letter5 = "W" Then Label10.Text = "W"
                If letter6 = "W" Then Label12.Text = "W"
                If letter7 = "W" Then Label14.Text = "W"
                If letter8 = "W" Then Label16.Text = "W"
                If letter9 = "W" Then Label18.Text = "W"
                If letter10 = "W" Then Label20.Text = "W"
            Else : wrong1.Text = "W"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "X" Then
                If letter1 = "X" Then Label2.Text = "X"
                If letter2 = "X" Then Label4.Text = "X"
                If letter3 = "X" Then Label6.Text = "X"
                If letter4 = "X" Then Label8.Text = "X"
                If letter5 = "X" Then Label10.Text = "X"
                If letter6 = "X" Then Label12.Text = "X"
                If letter7 = "X" Then Label14.Text = "X"
                If letter8 = "X" Then Label16.Text = "X"
                If letter9 = "X" Then Label18.Text = "X"
                If letter10 = "X" Then Label20.Text = "X"
            Else : wrong1.Text = "X"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "Y" Then
                If letter1 = "Y" Then Label2.Text = "Y"
                If letter2 = "Y" Then Label4.Text = "Y"
                If letter3 = "Y" Then Label6.Text = "Y"
                If letter4 = "Y" Then Label8.Text = "Y"
                If letter5 = "Y" Then Label10.Text = "Y"
                If letter6 = "Y" Then Label12.Text = "Y"
                If letter7 = "Y" Then Label14.Text = "Y"
                If letter8 = "Y" Then Label16.Text = "Y"
                If letter9 = "Y" Then Label18.Text = "Y"
                If letter10 = "Y" Then Label20.Text = "Y"
            Else : wrong1.Text = "Y"
                wrongtotal = wrongtotal + 1
            End If
            If Guess1 = "Z" Then
                If letter1 = "Z" Then Label2.Text = "Z"
                If letter2 = "Z" Then Label4.Text = "Z"
                If letter3 = "Z" Then Label6.Text = "Z"
                If letter4 = "Z" Then Label8.Text = "Z"
                If letter5 = "Z" Then Label10.Text = "Z"
                If letter6 = "Z" Then Label12.Text = "Z"
                If letter7 = "Z" Then Label14.Text = "Z"
                If letter8 = "Z" Then Label16.Text = "Z"
                If letter9 = "Z" Then Label18.Text = "Z"
                If letter10 = "Z" Then Label20.Text = "Z"
            Else : wrong1.Text = "Z"
                wrongtotal = wrongtotal + 1
            End If
End if


Is This A Good Question/Topic? 0
  • +

Replies To: How to fix a problem with Output of a Program

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,355
  • Joined: 02-June 10

Re: How to fix a problem with Output of a Program

Posted 15 November 2012 - 07:55 PM

Oh you have GOT to be kidding with this.
This is for your FINAL?
Cutting to the chase: The problem is line 450. That's where you capital Z is coming from.
Hint: When you play the game try setting the capslock on.

Please do a search here on DIC for "hangman". There are at least 50 threads from other students doing this.

Hangman tends to be an application of less than 150 lines even when one gets really fancy with it.

This approach you have taken of pure brute force with hundreds of lines of if checks indicates that you learned nothing from the chapters on <hint> for loops <hint>.

Please, read over some of the other threads for hangman and see how others have approached this, conceptually.
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How to fix a problem with Output of a Program

Posted 15 November 2012 - 08:19 PM

Anguishedsix50:= You're too Control focused.

You need so practice of the basics of the language and programming.
  • Collections (Array, List etc)
    Eg. the letters guessed so far.
  • Looping (For, ForEach, While erc)
    Eg. game play
  • Methods (Functions and Subroutines)
    What about a function that return the hangman style version of the guess phrase based on the letters that have been guessed so far?


Implement Hangman as a Console Application.
Simple overview of the hangman game.
Also you'll need to think about the possible states the game can be in.
Start Wrong 1 Wrong 2 Guessed Hung etc

Intro
Do
  Play A Game
Until Player Doesn't want to play anymore
Exit 

Play A Game
  Get word to guess.
  While still valid play
    Display Hangman Stuff
    Do
      What does player want to do?
    Until valid input
    What to do?
      Guess Letter:= Do letter guess stuff
      Guess Phrase:= Do phrase guess stuff
  End While
  How did the game end?
    Player Lost:= Do player lost stuff
    Player Won:= Do player won stuff


This post has been edited by AdamSpeight2008: 15 November 2012 - 08:36 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1