Problem with potentiometer and Arduino. Pls help

hey. I've been asked to program a sensor that is regulated by a potentiometer. While most of the design is done, i faced a problem where i kept getting a constant high or low (1023 or 0) for my pot. I disconnected everything but my pot (50k) and tried the most basic tests provided in arduino tutorial. When i connected all three pins( outer pins to gnd and 5v and middle to A0 input), and ran the Serial moniter, I only manage to get 0. For some reason, my bottom pin and middle pin seem to be shorted. However when I checked using a multimeter, the potentiometer was functioning perfectly.

The code i used is this

int a=A0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(a,INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(a);
// print out the value you read:
Serial.println(sensorValue);
delay(1000); // delay in between reads for stability
}

Where do you think my error is? I've checked online everywhere but seem to be getting the same problem. I've tried it on Uno smd version, Uno R3 and Arduino 2560 Mega.

Would someone tell me where I'm going wrong?

Sorry found my solution. Turns out my potentiometer wasn't working.

A hint for your code:

Initialize your variable only once at the start. Don't initialize it every time you run the loop. I don't know if this will make you a problem but it is at least better style:

int a = A0;
int sensorValue = 0;
...

void loop() {
...
sensorValue = analogRead(a);
...
}

Elektrix