-4
 int num1 , num2;
 bool equel ;
 equel =((num1 % 10 == num2 % 10 || num1 % 10 == num2 / 10) && (num1 / 10 == num2 / 10 || num1 / 10 == num2 % 10));

     Console.WriteLine("enter two numbers");
     Console.WriteLine("enter the first two digir number");
     num1 = int.Parse(Console.ReadLine());
     Console.WriteLine("enter the secound to digit numbers");
     num2=int.Parse(Console.ReadLine());

        if(equel)
            Console.WriteLine("the digits of the two numbers are equels");
        else
            Console.WriteLine("the digits of the two numbers are not equels");

Error 1 Use of unassigned local variable 'num1' D:\project visual studios\ConsoleApplication6\ConsoleApplication6\Program.cs 15 29 ConsoleApplication6

Liam
  • 27,717
  • 28
  • 128
  • 190
  • 5
    You haven't assigned a value to num1...Like it says – Liam Oct 27 '15 at 15:53
  • 1
    What do you think `Use of unassigned local variable 'num1'` means? You've *declared* your variables, but you haven't assigned them a value. How do you expect to perform modulo division on something that doesn't have a value? – sab669 Oct 27 '15 at 15:53
  • Just move the `equel =` to after where you set `num1` and `num2`. – Wai Ha Lee Oct 27 '15 at 15:55
  • The `equel=` line does not associate `equel` with that expression (as in "when num1 or num2 changes, I see the result immediately"), but tries to calculate it once at this position in the code, where num1 and num2 have no value yet. – Hans Kesting Oct 27 '15 at 15:58

2 Answers2

1

You're using 'num1' to calculate 'equel' without assigning a value to it. Move

equel =((num1 % 10 == num2 % 10 || num1 % 10 == num2 / 10) && (num1 / 10 == num2 / 10 || num1 / 10 == num2 % 10));

to after where you've finished reading values into num1 and num2

annm1991
  • 21
  • 6
0

Try to change the code in this way:

int num1 , num2;
bool equel ;

Console.WriteLine("enter two numbers");
Console.WriteLine("enter the first two digir number");
num1 = int.Parse(Console.ReadLine());
Console.WriteLine("enter the secound to digit numbers");
num2=int.Parse(Console.ReadLine());

equel =((num1 % 10 == num2 % 10 || num1 % 10 == num2 / 10) && (num1 / 10 == num2 / 10 || num1 / 10 == num2 % 10));


if(equel)
{
   Console.WriteLine("the digits of the two numbers are equels");
}
else
{
   Console.WriteLine("the digits of the two numbers are not equels");
}
Stefano Bafaro
  • 915
  • 10
  • 20