Error 1 A local variable named ‘userin’ is already defined in this scope
myclass.fillAccounts();
//int i = 0;
//while (i != 1)
string userin = null;
while (userin !="x")
{
//use the following menu:
Console.WriteLine("*****************************************");
Console.WriteLine("enter an a or A to search account numbers");
Console.WriteLine("enter a b or B to average the accounts");
Console.WriteLine("enter an x or X to exit program");
Console.WriteLine("*****************************************");
Console.Write("Enter option-->");
userin = Console.ReadLine();
if (userin == "a" || userin == "A")
{
myclass.searchAccounts();
}
else if (userin == "b" || userin == "B")
{
myclass.averageAccounts();
}
else if (userin == "x" || userin == "X")
{
break;
}
else
{
Console.WriteLine("You entered an invalid option");
}
}
}
}
}
Somewhere else in that method in the code you did not provide, you already have a line of code that says something like this:
You have later said:
Which is attempting to redefine a local variable. Get rid of the first variable declaration and you should be good to go for this issue. (You want to keep the declaration with the initial value, because you need that variable initialized by the time the
whilecondition is evaluated.)