1 Replies - 79 Views - Last Post: 23 August 2019 - 03:35 PM Rate Topic: -----

#1 GingerSnacks   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 23-July 19

Cannot See results of Console.ReadLine();

Posted 23 August 2019 - 03:05 PM

Hello C# programmers,

I am fairly new to C# and hopefully this goes in the general forums but i've come across a small issue in my code. Everything compiles great but the problem is that my code will not render the answer that the user types in. No errors are issued in the console and the else isn't needed. What is causing the issue?

namespace DecisionsIfElse
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Bob's big giveaway!");
            Console.Write("Choose a door: 1, 2 or 3");
            string userValue = Console.ReadLine();
            if (userValue == "1")
            {
                string message = "You won a car!";
                Console.WriteLine(message);

            }
            else if(userValue=="2")
            {
                string message = "You won a new boat!";
                Console.WriteLine(message);
            }
            else if(userValue=="3")
            {
                string message = "You won a new house!";
                Console.WriteLine(message);
            }
            Console.ReadLine();
        }
    }
}


:code:

This post has been edited by modi123_1: 23 August 2019 - 03:31 PM
Reason for edit:: In the future please use the [code] tag button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: Cannot See results of Console.ReadLine();

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15215
  • View blog
  • Posts: 60,899
  • Joined: 12-June 08

Re: Cannot See results of Console.ReadLine();

Posted 23 August 2019 - 03:35 PM

Please take the extra steps to remove line numbers and use the code tag button in the editor.

You should declare 'string message' once and not in each if section.

Finally - when I run it, and pick an option 1-3, it shows output in the console. Is that not what you are getting?

Side note - if you should have a final 'else' to handle input not expected.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1