quick noob question

This is a discussion on quick noob question within the C# Programming forums, part of the General Programming Boards category; hello, i downloaded microsoft visual c# 2008 a couple days ago and i've been trying to program stuff ever since, ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    5

    quick noob question

    hello, i downloaded microsoft visual c# 2008 a couple days ago and i've been trying to program stuff ever since, but i'm stuck and the sites i've visited don't really answer my question.

    i've tried making a game guessing game, the console generates a random number when i start the program, which is great, but when it asks me if i want to play again and i say yes, the number repeats, how can i fix that?

    here's the code.

    Code:
    using System;
    
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                int input;
                Random number = new Random();
                int n = number.Next(100);
    
            Start:
                Console.WriteLine("Guess a number between 1 and 100");
                input = int.Parse(Console.ReadLine());
    
                if (input > n)
                {
                    goto High;
                }
                else
                    if (input < n)
                    {
                        goto Low;
                    }
                    else
                        if (input == n)
                        {
                            goto Right;
                        }
    
    
            High:
                Console.WriteLine("Too High");
                input = int.Parse(Console.ReadLine());
    
                if (input > n)
                {
                    goto High;
                }
                else
                    if (input < n)
                    {
                        goto Low;
                    }
                    else
                        if (input == n)
                        {
                            goto Right;
                        }
    
    
            Low:
                Console.WriteLine("Too Low");
                input = int.Parse(Console.ReadLine());
    
                if (input > n)
                {
                  goto High;
                }
                else
                    if (input < n)
                    {
                       goto Low;
                    }
                    else
                        if (input == n)
                        {
                            goto Right;
                        }
    
    
            Right:
                Console.WriteLine("You guessed it!");
                goto New;
    
            New:
                Console.WriteLine("would you like to play again? yes/no");
                string answer = Console.ReadLine();
                switch (answer.ToLower())
                {
                    case "yes":
                        goto Start;
    
    
                    case "no":
                        goto End;
    
                    default:
                        Console.WriteLine("I don't understand, ");
                        goto New;
                }
            End:
                return;
            }
    
        }
    }
    keep in mind i only have like 10 hours of experience, on my own, so i'm really noob, thx.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The .Next is what gets you a new random number, so you should be sure that when you re-start that line happens.

    (And after you get that working, you can start looking at loops and if.)

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    5
    haha sweet.

    i got it to work, all i had to do was to put the label over the random generating code and not below, like it was.

    sweet, thx for the tip, i'll get to loops now.

    i think i'm learning a lot if i find things out myself, i'll be doing a course at college in january, but i want to know some stuff beforehand, which is why i'm messing around now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question (adding characters)
    By Cactus in forum C Programming
    Replies: 2
    Last Post: 09-24-2005, 03:54 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21