Sorry, I'm completely new to the programming world. I'm creating a console application that basically takes your input on whether you want to convert Celsius to Fahrenheit or vice-versa.
The problem I'm running into is:
"Error 3 A local variable named 'choice' cannot be declared in this scope because it would give a different meaning to 'choice', which is already used in a 'parent or current' scope to denote something else"
I tried looking at other examples, but they were far more complicated than my brain can understand for now.
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