❔ my code keeps on crashing. help me fix the code

『 』3/6/2023
Image
『 』3/6/2023
jdoodle.cs(146,29): error CS0136: A local variable named fromUnit' cannot be declared in this scope because it would give a different meaning tofromUnit', which is already used in a parent or current' scope to denote something else jdoodle.cs(154,29): error CS0136: A local variable namedtoUnit' cannot be declared in this scope because it would give a different meaning to toUnit', which is already used in aparent or current' scope to denote something else
jdoodle.cs(158,32): error CS0136: A local variable named value' cannot be declared in this scope because it would give a different meaning tovalue', which is already used in a parent or current' scope to denote something else jdoodle.cs(218,29): error CS0136: A local variable namedfromUnit' cannot be declared in this scope because it would give a different meaning to `fromUnit', which is already
『 』3/6/2023
its not working
『 』3/6/2023
Image
JJimmahdean3/6/2023
your issue is that else if (choice == 5) is inside else if (choice == 4)
JJimmahdean3/6/2023
else if (choice == 4)
{
    Console.WriteLine("Which unit would you like to convert from?");
    Console.WriteLine("1. Pounds");
    Console.WriteLine("2. Kilograms");

    int fromUnit = int.Parse(Console.ReadLine());

    Console.WriteLine("Which unit would you like to convert to?");
    Console.WriteLine("1. Pounds");
    Console.WriteLine("2. Kilograms");

    int toUnit = int.Parse(Console.ReadLine());

    Console.WriteLine("Enter the value to convert:");

    double value = double.Parse(Console.ReadLine());

    if (fromUnit == 1 && toUnit == 2)
    {
        value /= 2.205;
    }
    else if (choice == 5)
    {
you need to add another brace on line 138
TTheRanger3/6/2023
u cant define a variable of the same name twice in the same scope
TTheRanger3/6/2023
u can atleast reassign a value to it without redefining it
TTheRanger3/6/2023
 int fromUnit = int.Parse(Console.ReadLine()); // this is declaration and assigning a value

 fromUnit = int.Parse(Console.ReadLine()); // this is only assigning a value
『 』3/7/2023
Thanks for helping me fix the code
AAccord3/8/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.