对不起,我对编程世界完全陌生。我正在创建一个控制台应用程序,它基本上接受您是否要将摄氏温度转换为华氏温度或反之亦然的输入。
我遇到的问题是:
“错误 3 不能在此范围内声明名为‘选择’的局部变量,因为它会给‘选择’赋予不同的含义,‘选择’已在‘父或当前’范围中用于表示其他内容”
我尝试查看其他示例,但它们比我的大脑现在可以理解的要复杂得多。
namespace TemperatureApp
{
class Program
{
static void Main(string[] args)
{
int choice;
do
{
Console.WriteLine("Hi! This is a temperatue app");
Console.WriteLine("Press 1 for C to F or 2 for F to C");
//take the user input
int choice = Convert.ToInt32(Console.ReadLine());
if (choice == 1)
{
Console.WriteLine("Great, you chose C to F. Now enter the temp.");
int celcius = Convert.ToInt32(Console.ReadLine());
//next line use the formula and show answer
}
if (choice == 2)
{
Console.WriteLine("Great, you chose F to C. Now enter the temp.");
int fahrenheit = Convert.ToInt32(Console.ReadLine());
//next line use the formula and show answer
}
else
Console.WriteLine("That is not the right choice.");
//In this way, keep asking the person for either 1 or two
}
while (choice != 1 || choice != 2);
Console.ReadLine();
}
}
}