Click here to Skip to main content
15,918,125 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

Am i doing something wrong here pls? I think i might have a problem in the while loop since all the Console.WriteLine commangs are underlined in red after that line.

C#
namespace myDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int option;
            bool state = true;
            public int Option
            {
                get
                {
                    return option;
                }
                set
                {
                    if (value == 0 || value > 16)
                    {
                         Console.WriteLine("Invalid Option");
                    }
                    else
                    {option = value;}
                }
            }

            while(state = true)
            {
                Console.WriteLine("Please Enter the Ocupation");
                Console.WriteLine("1. Director");
                Console.WriteLine("2. Councilor");
                Console.Clear();
                Option = Console.ReadLine();


                switch(int Option)
                {
                    case 1:
                    {
                        Console.WriteLine("Displaying Director Options:");
                        Console.WriteLine("2. Display Students Details:");
                        Console.WriteLine("3. Display Councilors Details: ");
                        Console.WriteLine("4. Display Visits Details:");
                        Console.WriteLine("5. Add Student:");
                        Console.WriteLine("6. Remove Student:");
                        Console.WriteLine("7. Add Councilor:");
                        Console.WriteLine("8. Remove Councilor");
                        Console.WriteLine("9. Change Councilor Available Hours");
                        Console.WriteLine("10. Add Visit");

                    }


                }
            }
        }
    }
}


Screenshot: http://s2.postimage.org/osh5yy9op/Capture.jpg[^]
Posted
Updated 28-Dec-12 6:20am
v2

C#
while (state = true)

is always true, you mean:
C#
while (state == true)

Given the above, and your link, I think you should spend some more time rereading your reference guide on C# expressions and statements.
 
Share this answer
 
Comments
Thomas Daniels 28-Dec-12 12:26pm    
It's more than that. He created a property into the Main method.
Richard MacCutchan 28-Dec-12 12:42pm    
I didn't read beyond that as you seem to have covered all the other pieces.
Gilmore Sacco 28-Dec-12 12:52pm    
hey guys a very big thanks to both of you for your support :D
Hi,

Change
C#
switch(int Option)

into:
C#
switch (Option)

Also, change
C#
case 1:
{
       Console.WriteLine("Displaying Director Options:");
       Console.WriteLine("2. Display Students Details:");
       Console.WriteLine("3. Display Councilors Details: ");
       Console.WriteLine("4. Display Visits Details:");
       Console.WriteLine("5. Add Student:");
       Console.WriteLine("6. Remove Student:");
       Console.WriteLine("7. Add Councilor:");
       Console.WriteLine("8. Remove Councilor");
       Console.WriteLine("9. Change Councilor Available Hours");
       Console.WriteLine("10. Add Visit");

 }

into:
C#
case 1:
       Console.WriteLine("Displaying Director Options:");
       Console.WriteLine("2. Display Students Details:");
       Console.WriteLine("3. Display Councilors Details: ");
       Console.WriteLine("4. Display Visits Details:");
       Console.WriteLine("5. Add Student:");
       Console.WriteLine("6. Remove Student:");
       Console.WriteLine("7. Add Councilor:");
       Console.WriteLine("8. Remove Councilor");
       Console.WriteLine("9. Change Councilor Available Hours");
       Console.WriteLine("10. Add Visit");
       break;

You don't need to use brackets. Don't forget break; before a next case of before the end of the switch.
Read more about switch here:
http://msdn.microsoft.com/en-us/library/06tc147t%28v=vs.110%29.aspx[^]

[EDIT]

Also, change this:
C#
Option = Console.ReadLine();

into this:
C#
try
{
      Option = Convert.ToInt32(Console.ReadLine());
}
catch
{
      Console.WriteLine("Input string isn't in a correct format.");
     continue; // use 'continue' only in a loop
}


[EDIT]

I'm sorry, but I found a few mistakes after I saw your screen shot.
First:
C#
public int Option
           {
               get
               {
                   return option;
               }
               set
               {
                   if (value == 0 || value > 16)
                   {
                        Console.WriteLine("Invalid Option");
                   }
                   else
                   {option = value;}
               }
           }

You create a property INTO a function. That's not possible. Read more about properties:
http://msdn.microsoft.com/en-us/library/x9fsa0sw%28v=vs.80%29.aspx[^]
Second:
Don't use
C#
while (state = true)

Use
C#
while (state == true)

Read more about the == operator:
http://msdn.microsoft.com/en-us/library/53k8ybth.aspx[^]
 
Share this answer
 
v5
Comments
Gilmore Sacco 28-Dec-12 12:12pm    
Hello ProgramFOX,
Thanks for your quick reply and detailed solotion. I made the suggested solution but still the problem persists. I would like to upload a screenshot but i dont know how :(
Thomas Daniels 28-Dec-12 12:15pm    
You can't upload a screen shot. If you want to show an image, you need to upload an image on another site and posting a link here.
Gilmore Sacco 28-Dec-12 12:20pm    
I have added a screenshot in the question :D
Thomas Daniels 28-Dec-12 12:25pm    
I updated my answer.
Gilmore Sacco 28-Dec-12 12:55pm    
Good bless you sir. I was instruced my my lecturer to always use properties as this can help me control the user input. I did not know that i could not usee it thaht way. I did all the suggestions and it howks great now. Thanks alot and i appreciate alot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900