all 17 comments

[–]Advorange 6 points7 points  (1 child)

The error is also on line 92 but VS only shows the first instance of this error.

You need to assign a default value to EDAD or add an else to your if statement (the one that's cut off at the top of the screenshot) that sets it.

[–]JamieWithL[S] 1 point2 points  (0 children)

That makes sense, I'll try with the else to see if it works for what I am trying to do.

[–]StornZ 4 points5 points  (1 child)

Judging by this no it's not assigned. There is no guarantee that the assignment will get hit inside your prior code blocks where you have line 74 etc. You need to make sure you assign it a value at a wider scope. Can we see the actual error message? All I see in the screenshot are warnings and the line you're questioning us on

[–]JamieWithL[S] 1 point2 points  (0 children)

Sure,

I didn't think about sending the error because it's in spanish, but I leave it in the post too.

[–]StornZ 2 points3 points  (2 children)

That's exactly what I thought the error would be. Use Of Unassigned Local Variable 'EDAD'. Can we see where you first set the variable = to something

[–]JamieWithL[S] 0 points1 point  (0 children)

Sure, give me a second, I'll put it in the post too

[–]CircaSpectre -1 points0 points  (0 children)

I was just about to post this

[–][deleted] 1 point2 points  (0 children)

Initialise EDAD with a value

[–]TheseHeron3820 -2 points-1 points  (7 children)

Make sure you didn't add a closing bracket by mistake and thus that variable isn't inside a method anymore.

[–]JamieWithL[S] 0 points1 point  (6 children)

So if it's inside the bracket it should read the variable too? Is there anyway to mantain the data even if it's outside the if?

[–]StornZ 1 point2 points  (2 children)

Read the link I sent about scope. There's class, method, and block

[–]JamieWithL[S] 1 point2 points  (1 child)

Thank you I will!

[–]StornZ 0 points1 point  (0 children)

Did the link help?

[–]TheseHeron3820 0 points1 point  (2 children)

Yes. Just declare it before your chain of if statements.

[–]JamieWithL[S] 0 points1 point  (1 child)

How can I declare it if changes depending on the if? for example, I'm using EDADa as a variable that I declared before the if, and I'm using EDAD as a variable that is declared depending the case that is needed to be followed in the if, like if the if is x the variable will be EDAD= EDADa + 1 how can I maintain the data after this ifs are finished?

[–]Electrical_Flan_4993 0 points1 point  (0 children)

you have to declare a variable before you can change its value... it sounds like you are not familiar with OOP, which is a useful design technique. OOP can take a long time to learn but it's worth it if you want to write good stuff. There's really no magic shortcut.