Ive redeclared my int how do I reset it?- yep im a newb

I have a simple code to run on an Arduino Mega controlling 17 relays. Originally i wrote it where I had each relay listed for high and low and a delay in between. I figured their was a better way so I started to play around with int. The problem Im running into is ive declared my int in "STEPS" and then am trying to reset it to 1 in "GATE". This seems to upsets the Arduino overlords. Im sure their is a better way hope someone can help me out.

#define STEP(s) 1-17... //this is just to truncate my code I have each relay defined.
int n = 1;
long STEP(n);
long RandNumber;
void setup()
{
pinMode(STEP1, OUTPUT... //I have 1-17 defined as output truncated for the post
}
void loop()
{
STEPS:
digitalWrite(STEP,LOW); // Turns ON Relay(n)
delay(1000); // Wait 1 seconds
digitalWrite(STEP,HIGH); // Turns OFF Relay(n)
int n=n+1 ; // increase n by 1
if (n >= 17) {goto GATE;} // end loop if n=17
else goto STEPS; // go to next point
GATE:
digitalWrite(RELAY17,LOW); // Turn ON Relay 17
delay(10000); // Wait 10 seconds
digitalWrite(RELAY17,HIGH); // Turn OFF Relay 17
int n=1 ; // Reset (n) to 1
RandNumber = random(5000,20000); // establish random range
delay(RandNumber); // delay for random seconds
goto STEPS;} // go to starting point
}

What do you think this is doing?

long STEP(n);

To paraphrase Inigo Montoya: "I do not think that means what you think it means...".

Regards,
Ray L.

I thought that was declaring my variable of STEP with the integer of (n). Guessing by your loaded question it is not and you have insight for me.

It appears that you don't like loops. First, get rid of the #defines and give each relay an entry in an array, like:

int relays[17]; // Valid indexes are 0 through 16

The definition above should be placed before setup()

This code:

STEPS:
   digitalWrite(STEP,LOW);         // Turns ON Relay(n)
   delay(1000);                        // Wait 1 seconds
   digitalWrite(STEP,HIGH);       // Turns OFF Relay(n)
   int  n=n+1 ;                       // increase n by 1
     if (n >= 17) {goto GATE;}  // end loop if n=17
     else goto STEPS;              // go to next point

would more often be written as:

   int n;

   for (n = 0; n < 17; n++) {
      digitalWrite(relays[n], LOW);
      delay(1000);
      digitalWrite(relays[n], HIGH);
   }

Your code then redefines variable n again, which is going to piss off the compiler. Get rid of it. This section of code:

GATE:
 digitalWrite(RELAY17,LOW);    // Turn ON Relay 17
 delay(10000);                      //  Wait 10 seconds
 digitalWrite(RELAY17,HIGH);  // Turn OFF Relay 17
 int n=1 ;                             // Reset (n) to 1
 RandNumber = random(5000,20000); // establish random range
 delay(RandNumber);             // delay for random seconds
 goto STEPS;}

needs to be changed to something like:

   digitalWrite(relays[16], LOW);
   delay(10000);                           // Really? Are you going to make a sandwich or something?
   digitalWrite(relays[16], LOW);
   RandNumber = random(5000, 20000);  // Make coffee to wash the sandwich down?
   delay(RandNumber);

There's no need for GATE; you never use it. Also, you should call randomize() in setup(). These changes are a start...more work to be done.

thank Econjack for offering some solid solutions. Coffee / Sandwich.... Yes they are long delays. This is for a Halloween prop of 16 foot prints, light up in my yard, then a gate to swing open and closed for 10 seconds. Then a random delay before it repeats.

Delta_G:

int n = 1;

If you want to use the same variable you already created, then you don't put the type.

n = n + 1;

without the "int" will use the variable n that was already in existence.

Assuming that it is in scope and the compiler can see it. If n is defined as a global variable before setup() it is visible in the whole program. If you define it in setup() it is only visible in setup() and cannot be used in loop() or any other function.

If n is defined as a global variable before setup() it is visible in the whole program.

Clearly, the OP is having some trouble with the idea of scope. Technically, the quote should be:

If n is defined as a global variable before setup() it is visible in the whole program at all points in the current source code file.

If there are multiple source files that comprise the program, the extern keyword would have to be used in the other files to have access to the variable defined in the current source file. Yeah, it's a bit picky, but he may as well learn the details at the outset.

But is that true, since all the .ino's are munged together? The concept of a single source file in the Arduino IDE is a bit murky.

@Delta-G. Correct...and often library ccp files come into play during testing.

ok im lost... scope?,multiple ino?, yes Im very new to C++ programming (programming in general for that matter). Ill stick with my original code for now and figure this out later.

Regardless I truly appreciate the help and obviously need to do some more research into C++/Arduino...