What is my mistake in the code?

Hi everyone i was trying to make a color game where we have to keep in memory the color sequence emitted my the LEDs and give type in the same sequence in the serial monitor. I don’t How this part of the code is wrong so please help me out.

Here is the Program

int randomInt;
int memory[4];
char answer[4];
char takeIn;

void setup(){
  Serial.begin(115200);
  randomSeed(analogRead(0));
  pinMode(13,1);
  pinMode(12,1);
  pinMode(11,1);
  pinMode(10,1);
}

void loop(){
  for(int i=1;i<=4;i++){
  randomInt = random(1,5);
  switch(randomInt){
    case 1:
    blinkLed(13);
    delay(150);
    break;
    case 2:
    blinkLed(12);
    delay(150);
    break;
    case 3:
    blinkLed(11);
    delay(150);
    break;
    case 4:
    blinkLed(10);
    delay(150);
    break;
  }
  memory[i]=randomInt;
  delay(100);
  }
  for(int i = 1; i<=4; i++){
 while(Serial.available()){
  delay(10);
  char c = Serial.read();
  if(c == '\n'){break;}
  answer[i] = c;
 }
  }
  if(memory[1]==answer[1] $ memory[2]==answer[2] $ memory[3]==answer[3] $ memory[4]==answer[4]){
    Serial.println("Correct");
  }
  else{Serial.println("Wrong");}
}

void blinkLed(int LED){
  digitalWrite(LED,1);
  delay(150);
  digitalWrite(LED,0);
}

Here is the error:

Arduino: 1.6.10 (Windows 10), Board: "Arduino/Genuino Uno"

sketch_jul31a:47: error: stray '

I know it looks like a headache please help in program

if(memory[1]==answer[1] $ memory[2]==answer[2] $ memory[3]==answer[3] $ memory[4]==answer[4]){

^

sketch_jul31a:47: error: stray ’


I know it looks like a headache please help in program

sketch_jul31a:47: error: stray '

I know it looks like a headache please help in program

sketch_jul31a:47: error: stray ’


I know it looks like a headache please help in program

sketch_jul31a:47: error: stray '

I know it looks like a headache please help in program

sketch_jul31a:47: error: stray ’


I know it looks like a headache please help in program

C:\Users\Raebel Christo\Desktop\sketch_jul31a\sketch_jul31a.ino: In function 'void loop()':

sketch_jul31a:47: error: expected ')' before 'memory'

   if(memory[1]==answer[1] $ memory[2]==answer[2] $ memory[3]==answer[3] $ memory[4]==answer[4]){

                              ^

exit status 1
stray '

I know it looks like a headache please help in program

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.


I know it looks like a headache please help

(deleted)

And one should also remember that the index into an array starts at zero and not at one.

So the full corrected version of that line

if(memory[0]==answer[0] && memory[1]==answer[1] && memory[2]==answer[2] && memory[3]==answer[3]){

You can also use memcmp to compare the two variables.

Looks like a nice opportunity for a FOR loop

...R

I haven’t rested this since I don’t have the LED’s, but something along these lines should work and it is a little simpler:

#define PASSES  4

int randomInt;
int memory[PASSES];
char answer[PASSES];
char takeIn;

int LEDs[] = {0, 13, 12, 11, 10};

void setup() {
  Serial.begin(115200);
  randomSeed(analogRead(0));
  pinMode(13, 1);
  pinMode(12, 1);
  pinMode(11, 1);
  pinMode(10, 1);
}

void loop() {
  for (int i = 1; i <= PASSES; i++) {
    randomInt = random(1, 5);
    blinkLed(LEDs[randomInt]);
    memory[i] = randomInt;
    delay(100);
  }
  for (int i = 1; i <= PASSES; i++) {
    while (Serial.available()) {
      delay(10);
      char c = Serial.read();
      if (c == '\n') {
        break;
      }
      answer[i] = c - '0';    // Make it a numeric, not a char
    }
  }
  if (memcmp(memory, answer, sizeof(memory)) == 0) {
    Serial.println("Correct");
  }
  else {
    Serial.println("Wrong");
  }
}

void blinkLed(int LED) {
  digitalWrite(LED, 1);
  delay(150);
  digitalWrite(LED, 0);
  delay(150);
}