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

You're trying to use a variable called ledpin and you haven't told it anything about ledpin. I'd guess you haven't copied the complete program. Have another look at wherever you got the program from, there should be an extra line at the top declaring ledpin.

Steve