我是编写代码的新手,我了解一些,但我无法使某些事情发挥作用。
我希望这让用户先选择一个类别,然后再让他们访问一个类别,但我收到错误消息“使用未分配的局部变量”。我做错什么了吗?
public static void Main(string[] args)
{
bool CalculateSavings, Grades;
if (CalculateSavings == true)
{
int MySavings, Allowance, Food, Transportation, WeeklySavings, MonthlySavings;
Console.WriteLine("Input your daily allowance:");
Allowance = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input your daily food expenses:");
Food = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input your daily transportation expenses:");
Transportation = Convert.ToInt32(Console.ReadLine());
{
MySavings = Allowance - (Food + Transportation);
Console.WriteLine("Your calculated daily savings: {0}", MySavings);
WeeklySavings = MySavings * 5;
Console.WriteLine("Your calculated weekly savings: {0}", WeeklySavings);
MonthlySavings = WeeklySavings * 4;
Console.WriteLine("Your calculated monthly savings: {0}", MonthlySavings);
Console.ReadKey();
}
}
else if (Grades == true)
{
double Filipino, English, Science, Math, History, Average;
Console.WriteLine("Input grade in Filipino subject:");
Filipino = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input grade in English subject:");
English = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input grade in Science subject:");
Science = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input grade in Math subject:");
Math = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input grade in History subject:");
History = Convert.ToDouble(Console.ReadLine());
Average = (Filipino + English + Science + Math + History) / 5;
Console.WriteLine("Overall grade average: {0}", Average);
Console.ReadLine();
}
}
}
}
让用户先选择一个类别,然后再让他们访问一个类别,但我收到错误消息“使用未分配的局部变量”。