Comparing analog signals

So I pieced together a code:

int analogPin = A5;
int raw = 0;
int Vin = 5;
float Vout = 0;
float R1 = 1000;
float R2 = 0;
float buffer = 0;

void setup()
{
 Serial.begin(9600);
}

void loop()
{
  raw = analogRead(analogPin);
  if(raw){
    buffer = raw * Vin;
    Vout = (buffer)/1024.0;
    buffer = (Vin/Vout) - 1;
    R2= R1 * buffer;
    Serial.print("Vout: ");
    Serial.println(Vout);
    Serial.print("R2: ");
    Serial.println(R2);
    delay(1000);
}
}

It's able to read the unknown value, for some it reads 3 over though (i.e. if the unknown is supposed to be 1.5k ohm it reads 1.503k).