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

The compiler message is completely accurate.
You are calling pinMode with a variable 'ledpin'
pinMode(ledpin,OUTPUT);

You need to declare the variable so that the compiler knows what type it is and you need to assign a value to it.

See #2