Я работаю над заданием для класса, и я не могу его скомпилировать. Я продолжаю получать «Использование неназначенной локальной переменной»
для multiplierString
и MultiplcandString
. Они объявлены в верхней части основного, но, похоже, не присваивают им значения внутри циклов while. Если я заставляю значение за пределами цикла, ошибка исчезает. Любая помощь будет оценена по достоинству. Благодарю.
Что здесь происходит?
static void Main()
{
bool goodInput = false;
ConsoleKeyInfo cki;
string multiplicandString;
string multiplierString;
string endProduct;
string prompt;
string response;
Int64 TryNumber;
prompt = "This program will multiply two numbers of reasonable length.";
Console.WriteLine(prompt);
Console.WriteLine();
prompt = "Press the Escape (Esc) key to quit or any other key to continue.";
cki = Console.ReadKey();
if (cki.Key != ConsoleKey.Escape)
{
while (!goodInput)
{
prompt = "Please provide the multiplicand: ";
Console.WriteLine(prompt);
response = Console.ReadLine();
if (Int64.TryParse(response, out TryNumber))
{
goodInput = true;
multiplicandString = "a"; //TryNumber.ToString();
}
else
{
Console.WriteLine();
prompt = "Invalid multiplicand entry. It must be all numbers.\a";
Console.WriteLine(prompt);
prompt = "Please try again.";
Console.WriteLine(prompt);
}//end if Int64.TryParse
}//end while ! goodInput
goodInput = false;
while (!goodInput)
{
prompt = "Please provide the multiplier: ";
Console.WriteLine(prompt);
response = Console.ReadLine();
if (Int64.TryParse(response, out TryNumber))
{
goodInput = true;
multiplierString = "a"; //TryNumber.ToString();
}
else
{
Console.WriteLine();
prompt = "Invalid multiplier entry. It must be all numbers.\a";
Console.WriteLine(prompt);
prompt = "Please try again.";
Console.WriteLine(prompt);
}//end if Int64.TryParse
}//end while ! goodInput
//multiplierString = "a"; //TryNumber.ToString();
endProduct = MultiplyByRectangle(multiplicandString, multiplierString);
Console.WriteLine("The result of the calculation is:");
Console.WriteLine("\t" + endProduct);
}//end Main()