How do I fix the error that says 'ledpin' was not declared in this scope?

and just for completeness, use the </> code tags when posting.
A little indenting never hurt either.

//declare global variables up here
int ledpin = 13;

void setup()
{
  Serial.begin(9600); 
  pinMode(ledpin,OUTPUT);
}

void loop() 
{
  if(Serial.available() > 0){
     val=Serial.read(); 
  }

  if(val=='R') 
  { 
    digitalWrite(ledpin,HIGH); 
    delay(500);
    digitalWrite(ledpin,LOW);
    delay(500); 
    Serial.println("HelloWorld!"); 
  }
}