error "sketch_dec05a:18: error: 'counter' was not declared in this scope"

I am a total noob.

I am reading the book Begining C for Arduino.

I am on page 62 and trying to put in the code as the book has it. Am I doing something Wrong?

Here is what I have:

/* alternate blink */

int ledred = 12;
int ledgreen = 13;

void setup(){
  pinMode (ledred, OUTPUT);
  pinMode (ledgreen, OUTPUT);
  void loop(){
    if (counter % 2 == 1) {
      digitalWrite (ledred, HIGH);
      digitalWrite (ledgreen, LOW);
    if (counter % 2 == 0){
      digitalWrite (ledred, LOW);
      digitalWrite (ledgreen, HIGH);
   counter = counter + 1;

You haven't told the computer that "counter" is a variable and what type of variable.
For example you could add it here:-

int ledred = 12;
int ledgreen = 13;
int counter =0;

Thanks, that did it.

This is probably a dumb question, but how does it know that the led’s are pins and the counter is not?

Is it because of the digitalWrite lines?

It doesn't know. The variables ledred, ledgreen, and counter are all just numbers and nothing more. The digitalWrite function takes a number that corresponds to one of the pins. You are substituting a variable for that number. But in the end, it is just a number. The processor knows nothing more about it.

OK I see.

Thanks for the help. 8)