expected constructor, destructor, or type Error in programming Relay Board

Hi,
I’m trying to set up an 8-way relay board to randomly switch on lights (and off again). The code is below. However, I keep getting an error stating: “expected constructor, destructor, or type conversion before ‘(’ token”. I think I’ve checked all the bracket pairs but still can’t get this error cleared. Can anyone help with this code error, please?

void setup() {
int i;
Serial.begin(9600);

int arr = {3, 4, 5, 6, 7, 8, 9, 10};
int n = sizeof(arr) / sizeof(arr[0]);
}

randomize (arr, n);

for (i - 0; i < n; i++)

Serial.print(arr*);*

  • Serial.print(" ");*
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    delay(1000);
    digitalWrite(arr[0], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(" "); //prints new line
    Serial.println(arr[0]); //prints pin-number
    delay(10000);
    digitalWrite(arr[0], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for a second
    digitalWrite(arr[1], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[1]); //prints pin-number
    delay(10000);
    digitalWrite(arr[1], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[2], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[2]); //prints pin-number
    delay(10000);
    digitalWrite(arr[2], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[3], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[3]); //prints pin-number
    delay(10000);
    digitalWrite(arr[3], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[4], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[4]); //prints pin-number
    digitalWrite(arr[4], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[5], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[5]); //prints pin-number
    delay(10000);
    digitalWrite(arr[5], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[6], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[6]); //prints pin-number
    delay(10000);
    digitalWrite(arr[6], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[7], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[6]); //prints pin-number
    delay(10000);
    digitalWrite(arr[7], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    digitalWrite(arr[8], LOW); // turn the LED off (LOW is the voltage level)
    Serial.println(arr[8]); //prints pin-number
    delay(10000);
    digitalWrite(arr[8], HIGH); // turn the LED on again
    delay(random(5000, 7000)); // wait for 5-15 seconds
    void swap (int *a, int *b)
    _ int temp = *a;_
    _ *a = *b;_
    _ *b = temp;_
    }}
    void randomize ( int arr[], int n )
    {
  • // Use a different seed value so that we don’t get same*
  • // result each time we run this program*
  • randomSeed(analogRead(A0));*
  • // Start from the last element and swap one by one. We don’t*
  • // need to run for the first element that’s why i > 0*
  • for (int i = n - 1; i > 0; i–)*
  • {*
  • long j = random(0, n);*
    _ swap(&arr*, &arr[j]);_
    _
    }_
    _
    }*_

Where is your loop function?

Where is the closing brace before the swap function?

Posting using code tags would prevent your code being mangled by the forum software.

Thanks for the feedback. I'm afraid I did overlook those two points and have amended the code accordingly. I'm still trying to get it to run but I need to continue my education to try to get it running as I want. Appreciate the help!
John

Posting using code tags would prevent your code being mangled by the forum software.

Read the how to use this forum sticky to see how to properly post code and error messages using code tags.

Post all of the code. We need to see how variables and objects are declared. Post the complete text of the error message. There is important information in the message that paraphrasing leaves out.

void setup()
{
  int i;
  Serial.begin(9600);

  int arr[] = {3, 4, 5, 6, 7, 8, 9, 10};
  int n = sizeof(arr) / sizeof(arr[0]);

  //// This was ending the setup() function prematurely
  //// }

  randomize (arr, n);

  //// Your 'loop variable initialization' does nothing
  //// for (i - 0; i < n; i++)

  //// Typically you would initialize 'i' to 0
  for (i = 0; i < n; i++)
    //// If you want more than one statement inside your 'for' loop you have to use brackets
    //// Adding an open bracket:
  {
    Serial.print(arr[i]);

    Serial.print("   ");
    //// Adding a close bracket:
  }

  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

  delay(1000);


  digitalWrite(arr[0], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println("   "); //prints new line
  Serial.println(arr[0]); //prints pin-number
  delay(10000);
  digitalWrite(arr[0], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for a second   //// No, wait for 5 to 7 seconds

  digitalWrite(arr[1], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[1]); //prints pin-number
  delay(10000);
  digitalWrite(arr[1], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[2], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[2]); //prints pin-number
  delay(10000);
  digitalWrite(arr[2], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[3], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[3]); //prints pin-number
  delay(10000);
  digitalWrite(arr[3], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[4], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[4]); //prints pin-number
  digitalWrite(arr[4], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[5], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[5]); //prints pin-number
  delay(10000);
  digitalWrite(arr[5], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[6], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[6]); //prints pin-number
  delay(10000);
  digitalWrite(arr[6], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[7], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[6]); //prints pin-number
  delay(10000);
  digitalWrite(arr[7], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  digitalWrite(arr[8], LOW);   // turn the LED off (LOW is the voltage level)
  Serial.println(arr[8]); //prints pin-number
  delay(10000);
  digitalWrite(arr[8], HIGH);    // turn the LED on again
  delay(random(5000, 7000));             // wait for 5-15 seconds

  //// This end of the setup() function was missing
}


void swap (int *a, int *b)
//// This open bracket of the swap() function was missing:
{

  int temp = *a;
  *a = *b;
  *b = temp;

}

//// This was an EXTRA end of the swap() function
//// }

void randomize ( int arr[], int n )
{
  // Use a different seed value so that we don't get same
  // result each time we run this program
  randomSeed(analogRead(A0));

  // Start from the last element and swap one by one. We don't
  // need to run for the first element that's why i > 0
  for (int i = n - 1; i > 0; i--)

  {
    long j = random(0, n);

    swap(&arr[i], &arr[j]);

  }
}

//// The required loop() function was missing.  It doesn't have to do anything.
void loop() {}