Hangman

Split From Necro

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

30 Replies - 1130 Views - Last Post: 14 June 2013 - 03:44 AM Rate Topic: -----

#16 Robin19  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 271
  • View blog
  • Posts: 550
  • Joined: 07-July 10

Re: Hangman

Posted 12 June 2013 - 10:26 AM

Put a breakpoint on line 64.
Was This Post Helpful? 0
  • +
  • -

#17 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 12 June 2013 - 11:29 AM

View PostCurtis Rutland, on 12 June 2013 - 07:27 AM, said:

Why should we continue to help when you haven't taken previous advice?

Because Im a high school studnet. Half the words you guys are saying are not making sense to me. If you just tell me what i have to change then I should be fine
Was This Post Helpful? 0
  • +
  • -

#18 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9057
  • View blog
  • Posts: 34,001
  • Joined: 12-June 08

Re: Hangman

Posted 12 June 2013 - 11:30 AM

Yeah, but if we just tell you then that would be cheating if you turned in the work without learning what's up!
Was This Post Helpful? 0
  • +
  • -

#19 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 12 June 2013 - 11:34 AM

Quote

Because Im a high school studnet.

I don't want to come across as rude when I say this, but we really don't care if you're a high school student. I was a high school student learning to program at one point too, as were many of our members. We know what it's like to be new to programming. We treat everyone the same way, though, and we have the same expectations of effort.

Quote

Half the words you guys are saying are not making sense to me.

Then you need to step back for a moment and do things like read the documentation and ask questions. We're all here because we enjoy helping others. Members who make a good faith effort get a lot more out of our help than members who don't want to do any thinking. This applies to any type of learning really.
Was This Post Helpful? 0
  • +
  • -

#20 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 12 June 2013 - 11:42 AM

Quote

Then you need to step back for a moment and do things like read the documentation and ask questions. We're all here because we enjoy helping others. Members who make a good faith effort get a lot more out of our help than members who don't want to do any thinking. This applies to any type of learning really.


ok ok. im sorry. but can you guys please just help me and then I will look on the internet and learn aboutit after. i did not mean to come across rude I just need help and I promise ill make an effort to work. just tell me in like words I would understand haha

This post has been edited by modi123_1: 12 June 2013 - 11:52 AM
Reason for edit:: fixed botched quote tags

Was This Post Helpful? 0
  • +
  • -

#21 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 12 June 2013 - 11:44 AM

What specifically don't you understand? Ask specific questions and you will get better results.

Quote

but can you guys please just help me

The responses you've gotten have been trying to help.
Was This Post Helpful? 0
  • +
  • -

#22 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 12 June 2013 - 11:47 AM

Its telling me that playerGuess is not displayed in the current context. This is found on the line right under "Console.WriteLine(guess);". Can you guys show me what I can do to make it into the current context?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Final_Project
{
    class FinalProject
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetWindowSize(80, 50);


            Console.WriteLine("        ___ ___");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("|__|   |   |   |");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("__________________");

            Console.WriteLine("\n\n");
            Console.WriteLine("Instructions: Try and guess the word");



            string[] wordBank = new string[10];
            wordBank[0] = "Math";
            wordBank[1] = "Computer Science";
            wordBank[2] = "Programs";
            wordBank[3] = "Equations";
            wordBank[4] = "Mr Lynch";
            wordBank[5] = "Calculator";
            wordBank[6] = "Hard Work";
            wordBank[7] = "Dedication";
            wordBank[8] = "Knowledge";
            wordBank[9] = "Mike Sperando";



            Random randGen = new Random();
            int generateRandomWord = randGen.Next(0, 9);
            int Length = wordBank[generateRandomWord].Length;
            string randomWord = wordBank[generateRandomWord];
            char[] guess = new char[Length];

            for (int p = 0; p < Length; p++)
                guess[p] = '*';

            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Please Enter a Guess");
                char playerGuess = char.Parse(Console.ReadLine());

                for (int m = 0; m < Length; m++)
                {
                    if (wordBank[generateRandomWord].LastIndexOf(playerGuess) == playerGuess)
                    {
                        Console.WriteLine("You have gussed the correct letter guess again!");
                    }
                    else
                    {
                        Console.WriteLine("WRONG guess again:)");
                    }

                }
            }
            
            Console.WriteLine(guess);
            
            if (playerGuess == generateRandomWord)
            {
                Console.WriteLine("You have solved the word correctly");
            }
            else
            {
                Console.WriteLine("You are wrong thanks for playing!");
            }
        }
    }
}


This post has been edited by macosxnerd101: 12 June 2013 - 11:48 AM
Reason for edit:: Please start using code tags. You have been asked a few times now.

Was This Post Helpful? 0
  • +
  • -

#23 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 12 June 2013 - 11:50 AM

Please use code tags: :code:. We have this request plastered around the site, and you have been asked before to use them.

As for your problem, you declare playerGuess in your while loop. Thus, it is local to your loop and cannot be accessed outside of your loop. You should declare the variable outside of your loop.
Was This Post Helpful? 0
  • +
  • -

#24 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 12 June 2013 - 11:57 AM

I did that and this is what I came up with. It is telling me I have unreachable code

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#25 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 12 June 2013 - 12:00 PM

You have an infinite loop, out of which you never break. Thus, you can't access any code after your loop.

In the future, please post your code using code tags, rather than as an image. It makes it easier if we need to copy your code to run some tests.
Was This Post Helpful? 0
  • +
  • -

#26 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: Hangman

Posted 12 June 2013 - 12:27 PM

You should take some time and write out on paper, via a flowchart, what it is you want your program to do.
Was This Post Helpful? 1
  • +
  • -

#27 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 13 June 2013 - 05:43 PM

Alright guys this is what I have come up with! Everything works my question is I need to make a variable for if you guess the word correct. I just need help making the variable for "win" Any one help? I am going to enter the code for this where the comments are near the end of the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Final_Project
{
    class FinalProject
    {
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetWindowSize(80, 50);


            Console.WriteLine("        ___ ___");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("|__|   |   |   |");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("|  |   |   |   |");
            Console.WriteLine("__________________");

            Console.WriteLine("\n\n");
            Console.WriteLine("Instructions: Try and guess the word");



            string[] wordBank = new string[10];
            wordBank[0] = "math";
            wordBank[1] = "computer science";
            wordBank[2] = "programs";
            wordBank[3] = "equations";
            wordBank[4] = "mrlynch";
            wordBank[5] = "calculator";
            wordBank[6] = "hardwork";
            wordBank[7] = "dedication";
            wordBank[8] = "knowledge";
            wordBank[9] = "mikesperando";



            Random randGen = new Random();
            int generateRandomWord = randGen.Next(0, 10);
            int Length = wordBank[generateRandomWord].Length;
            string randomWord = wordBank[generateRandomWord];
            string playerGuess = "0";
            double strike = 0;//number of strikes
            bool test, inGame = true, win = false;


                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("Please Enter a Guess");
                playerGuess = Console.ReadLine();
                
                

                while (inGame == true)
                {
                    test = wordBank[generateRandomWord].Contains(playerGuess);
                    if (test == true)
                    {
                        Console.WriteLine("You have gussed the correct letter guess again!");
                        
                        int numberofCorrectLetters = 0;
                        numberofCorrectLetters++;

                        if (numberofCorrectLetters == Length)
                        {
                            Console.WriteLine("you win!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("WRONG guess again:)");
                        strike++;
                        if (strike == 8)
                        {
                            inGame = false;
                            win = false;
                        }
                    }
                    /*if (Winning conditions)
                    {
                        inGame = false; win = true;
                    }*/
                    playerGuess = Console.ReadLine();
                }
            
            
        }
    }
}

This post has been edited by macosxnerd101: 13 June 2013 - 05:45 PM
Reason for edit:: Code tags! Use them!

Was This Post Helpful? 0
  • +
  • -

#28 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 13 June 2013 - 05:46 PM

You need to start using code tags: :code:. Seriously, they're plastered around the site and we've asked you half a dozen times. Please start using them, as per the rules. Code tags really make it easier to read your code.
Was This Post Helpful? 0
  • +
  • -

#29 Mikey1200  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 10-June 13

Re: Hangman

Posted 13 June 2013 - 05:48 PM

View Postmacosxnerd101, on 13 June 2013 - 05:46 PM, said:

You need to start using code tags: :code:/>. Seriously, they're plastered around the site and we've asked you half a dozen times. Please start using them, as per the rules. Code tags really make it easier to read your code.


I dont know how to use them
Was This Post Helpful? 0
  • +
  • -

#30 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10444
  • View blog
  • Posts: 38,682
  • Joined: 27-December 08

Re: Hangman

Posted 13 June 2013 - 06:05 PM

It's BBCode, which is similar to HTML. Seriously, quote a post with the syntax highlighted code or read my last post or anywhere else on the site. It's plastered everywhere how to use them.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3