对不起,我完全新的编程世界。我正在创建一个控制台应用程序,基本上可以根据您是否要将摄氏度转换为华氏度或反之亦然进行输入。局部变量名“选择”不能声明,因为它会给出不同的含义,“选择”
我遇到的问题是:
“错误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();
}
}
}
这里是否失败:'if(choice == 2)'? – Brian 2013-02-08 20:58:20