1 Attachment(s)
[RESOLVED] Help with increasing int!
case "north":
Console.WriteLine("Moved North");
int xCord;
xCord++;
int yCord = new int();
yCord = 0;
Console.WriteLine("(" + xCord + "," + yCord + ")");
break;
--
Hey, I'm new to C-sharp and am having trouble with int's.
I want to increase the xCord by value of 1, every time 'north' is entered and the loop run again.
But with this current code, it stays at 1 no matter how many times the loop runs.
Thanks in advance :)
Re: Help with increasing int!
Have you tried moving the "int xcoord" statement outside the case statement ? (same with ycoord).
Re: [RESOLVED] Help with increasing int!
Please go and study variable lifetime/scope in C#.
Re: [RESOLVED] Help with increasing int!
Quote:
Originally Posted by
ThermoSight
Have you tried moving the "int xcoord" statement outside the case statement ? (same with ycoord).
Quote:
Originally Posted by
BigEd781
Please go and study variable lifetime/scope in C#.
@ThermoSight, thankyou so much! Hours of frustration over.
@BigEd781, I've read that article now and I understand what I was doing wrong, thanks a bunch.