Thread: Console.Read

Results 1 to 4 of 4
  1. #1
    Gruntlyon's Avatar
    Join Date
    Feb 2012
    Gender
    male
    Location
    Everywhere!
    Posts
    231
    Reputation
    80
    Thanks
    485
    My Mood
    Angelic

    Console.Read

    So I wrote this code:
    Code:
    class Program
        {
            static void Main(string[] args)
            {
                char l;
                Console.WriteLine("Press 1, 2, 3, 4, or 5. OR you can press 'f' for something special!");
                l = (char)Console.Read();
                switch (l)
                {
                    case '1':
                        {
                            int q, a = '7';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            q = (int)Console.Read();
                            if (q == a)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
    
                    case '2':
                        {
                            int w, aw = '4';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            w = (int)Console.Read();
                            if (w == aw)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '3':
                        {
                            int e, awn = '2';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            e = (int)Console.Read();
                            if (e == awn)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '4':
                        {
                            int r, awns = '6';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            r = (int)Console.Read();
                            if (r == awns)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '5':
                        {
                            int t, awnse = '9';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            t = (int)Console.Read();
                            if (t == awnse)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case 'f':
                        {
                            Console.WriteLine("Happy fathers day tat!");
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("Thats.....not valid...");
                            break;
                        }
                }
            }
        }
    But after you type 1 or 2 or whatever and it says to guess a number it doesnt stop to let you guess, it just keeps going on to the end.
    Anyone know the problem?
    EDIT: Tat means dad in his language
    Last edited by Gruntlyon; 06-17-2012 at 09:32 AM.
    CATS WILL TAKE OVER THE WORLD WITH THEIR MONAY!!!!!!!!!!!

    10 Posts
    25 Posts
    50 Posts
    100 Posts
    150 Posts
    300 Posts
    500 Posts
    1000 Posts
    1500 Posts

    My Epic Sig I made:
    [img]https://gifninj*****m/animatedgifs/79036/gruntlyon.gif[/img]


    WTF Moments

    Confusing Stuff



    Epicly Weird

    U Mad Bro???!?!??


    Thats all.

  2. #2
    xDango's Avatar
    Join Date
    Apr 2012
    Gender
    male
    Posts
    1
    Reputation
    10
    Thanks
    0
    Use Console.ReadLine() not Read() like: l = char.Parse(Console.ReadLine()); or l = Console.ReadLine()[0];
    Read() will also read the carriage return, which is why it wasn't work right.

  3. #3
    Gruntlyon's Avatar
    Join Date
    Feb 2012
    Gender
    male
    Location
    Everywhere!
    Posts
    231
    Reputation
    80
    Thanks
    485
    My Mood
    Angelic
    Quote Originally Posted by xDango View Post
    Use Console.ReadLine() not Read() like: l = char.Parse(Console.ReadLine()); or l = Console.ReadLine()[0];
    Read() will also read the carriage return, which is why it wasn't work right.
    Oh, yea I figured it out thanks anyway /req close
    CATS WILL TAKE OVER THE WORLD WITH THEIR MONAY!!!!!!!!!!!

    10 Posts
    25 Posts
    50 Posts
    100 Posts
    150 Posts
    300 Posts
    500 Posts
    1000 Posts
    1500 Posts

    My Epic Sig I made:
    [img]https://gifninj*****m/animatedgifs/79036/gruntlyon.gif[/img]


    WTF Moments

    Confusing Stuff



    Epicly Weird

    U Mad Bro???!?!??


    Thats all.

  4. #4
    rabir007's Avatar
    Join Date
    Aug 2011
    Gender
    male
    Location
    Behind you...
    Posts
    2,323
    Reputation
    148
    Thanks
    1,925
    My Mood
    Bored
    Quote Originally Posted by Gruntlyon View Post
    So I wrote this code:
    Code:
    class Program
        {
            static void Main(string[] args)
            {
                char l;
                Console.WriteLine("Press 1, 2, 3, 4, or 5. OR you can press 'f' for something special!");
                l = (char)Console.Read();
                switch (l)
                {
                    case '1':
                        {
                            int q, a = '7';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            q = (int)Console.Read();
                            if (q == a)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
    
                    case '2':
                        {
                            int w, aw = '4';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            w = (int)Console.Read();
                            if (w == aw)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '3':
                        {
                            int e, awn = '2';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            e = (int)Console.Read();
                            if (e == awn)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '4':
                        {
                            int r, awns = '6';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            r = (int)Console.Read();
                            if (r == awns)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case '5':
                        {
                            int t, awnse = '9';
                            Console.WriteLine(" (Followed by *** ENTER ***)Enter a number bewtween 0 and 9:");
                            t = (int)Console.Read();
                            if (t == awnse)
                            {
                                Console.WriteLine("Correct!");
                            }
                            break;
                        }
                    case 'f':
                        {
                            Console.WriteLine("Happy fathers day tat!");
                            break;
                        }
                    default:
                        {
                            Console.WriteLine("Thats.....not valid...");
                            break;
                        }
                }
            }
        }
    But after you type 1 or 2 or whatever and it says to guess a number it doesnt stop to let you guess, it just keeps going on to the end.
    Anyone know the problem?
    EDIT: Tat means dad in his language

    (int)Console.Readline() is invalid, you only can (or you should) convert text to number with:
    int.Parse(Console.ReadLine())







Similar Threads

  1. [Help] Reading and writing to Modern Warfare 2 console?
    By HACKINGPIE in forum Call of Duty Modern Warfare 2 Coding / Programming / Source Code
    Replies: 4
    Last Post: 12-24-2011, 08:24 PM
  2. Just info , read it if you use the console.
    By BAkAlA in forum Call of Duty Modern Warfare 2 Private Servers
    Replies: 1
    Last Post: 07-27-2010, 12:05 AM
  3. Want games, consoles, game cards? read.
    By bensoanes24 in forum General
    Replies: 3
    Last Post: 03-17-2009, 12:15 PM
  4. Read Before Requesting
    By Chronologix in forum Help & Requests
    Replies: 0
    Last Post: 01-14-2006, 04:56 PM
  5. Rules - Read Before Posting
    By Dave84311 in forum General Game Hacking
    Replies: 0
    Last Post: 12-31-2005, 11:13 AM