0

since I'm a bloody beginner, I'll need some help here:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gauss_Algorithmus
{
    class Program
    {
        static void Main(string[] args)
        {
            if (x1 > 0 && x2 > 0)
            {
                 x02 = (x2 * x1) - (x1 * x2); 
                 y02 = (y2 * x1) - (x1 * y2);
                 z02 = (z2 * x1) - (x1 * z2);
                 d02 = (d2 * x1) - (x1 * d2);
            }
            Console.WriteLine("2.:   " + x02 + "x + " + y02 + "y + " + z02 + "  d02);
       }
   }

It says:

Use of unassigned local variable "x01, etc....

I understand the error and know that x01 is just defined in a local scope, but don't know how to fix it since x01, etc. needs to be defined inside the if loop.

I hope you can help me out guys, thanks in advance..

3
  • 3
    Those variables are never defined, so kinda hard to discuss; the definition position is critical here (as is the exact position where things are assigned values). Can you edit it to show a version that at least shows the same error as the one you are reporting? Commented Jun 14, 2016 at 10:28
  • 3
    And you never use x01 either, which means this isn't the code producing this error. Please provide a minimal reproducible example. Commented Jun 14, 2016 at 10:30
  • you are also missing a } that would close the scope of the namespace function Commented Jun 14, 2016 at 10:38

2 Answers 2

1

The best advise is to do a getting started with C# tutorial.

Specifically answering your question there are two things wrong:

  1. You need to declare the variables. Basically using var x02 = (x2 * x1) - (x1 * x2); etc
  2. The usage of the variables needs to be in the same scope. Either you have to move the Console.WriteLine inside the if block or you need to declare and initialize the variables before the if block like this: var x02 = 0; etc
Sign up to request clarification or add additional context in comments.

Comments

0

As suggested earlier, see a good C# tutorial for beginners.

To make your example code work, do the following:

Declare variables first, maybe of integer types, e.g

int x1, x2, y1, y2, z1, z2, d1, d2, x02, y02, z02, d02;

Initialize them before using, e.g x1 = *value*; y1 = *value* ...

Reformat the Console.WriteLine statement, e.g: Console.WriteLine("2.: {0}", x02); //for displaying value of x02

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.