Error "use of unassigned local variable" when using do while loop and bool variable in c# -


i have problem mentioned in title, need rip of annoying error.

here's code:

bool moreemp; int arrayplus; string doitagain; arrayplus = -1;  string[,] employees = new string[10, 10];  {     arrayplus++;     console.writeline("please enter employee's number");     employees[0, arrayplus] = console.readline();     console.readline();     console.writeline("please enter employee's name");     employees[1, arrayplus] = console.readline();     console.readline();     console.writeline("please enter employee's age");     employees[2, arrayplus] = console.readline();     console.readline();     console.writeline("please enter employee's official position ");     employees[3, arrayplus] = console.readline();     console.readline();     console.writeline("please enter employee's salary");     employees[4, arrayplus] = console.readline();     console.readline();     console.writeline("do want add more employees list? y or n.");      doitagain = console.readline();      if (doitagain == "y" || doitagain == "y")     {        moreemp = true;     }     else if (doitagain == "n" || doitagain == "n")     {        moreemp = false;     }     else     {        console.writeline("you have entered invalid information");     } }  while (moreemp == true); 

so assigned bool variable if statement, still don't know why made such error this. thank reading question , me out :d.

you assign value in if, , else if, not in else clause. if final else hit, value never assign variable.

looking @ code, should assigned true value in else. fix problem you.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -