Error: expected declaration before } token

My arduino is throwing this whenever I attempt to compile, sorry for being a silly noob, but what does this mean? I'd paste the codeblock here but it is really really long, because I am playing audio via a list of frequencies.

Remove most of the frequencies from the list. Do you still get the error? If you do, post that code.

please just paste it.
You're likely missing a matching {.

By the way, the Arduino is not throwing the error. It's your pc/laptop throwing the error when you try to upload the code to the arduino. The code is not actually getting to the Arduino.

#include <PCM.h>
#include <LiquidCrystal.h>
const unsigned char sample[] PROGMEM = {
  123,
  123,
  125,
  124,
  126,
  126,
  127,
  127,
  124,
  122,
  118,
  118,
  117,
  119,
  122,
  122,
  122,
  122,
  121,
  121,
  124,
  124,
  126,
  126,
  123,
  123,
  122,
  123,
  123,
  123,
  124,
  122,
  123,
  122,
  121,
  122,
  122,
  123,
  124,
  125,
  125,
  125,
  123,
  124,
  125,
  126,
  128,
  129,
  131,
  130,
  128,
  128,
  127,
  127,
  128,
  130,
  130,
  129,
  128,
  126,
  126,
  126,
  128,
  130,
  130,
  130,
  128,
  128,
  126,
  127,
  130,
  132,
  133,
  132,
  131,
  129,
  128,
  129,
  130,
  130,
  131,
  130,
  130,
  129,
  130,
  131,
  130,
  131,
  128,
  127,
  128,
  127,
  129,
  129,
  130,
  129,
  129,
  129,
  131,
  133,
  133,
  135,
  133,
  132,
  131,
  129,
  129,
  127,
  128,
  128,
  129,
  132,
  131,
  131,
  129,
  127,
  126,
  126,
  129,
  131,
  131,
  131,
  130,
  128,
  127,
  127,
  127,
  128,
  128,
  128,
  127,
  125,
  125,
  124,
  125,
  128,
  128,
  129,
  127,
  123,
  123,
  121,
  123,
  125,
  128,
  129,
  129,
  128,
  126,
  126,
  126,
  127,
  128,
  129,
  128,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  128,
  128,
  128,
  128,
  127,
  128,
  127,
  127,
  127,
  127,
  127,
  128,
  127,
  127,
  127,
  127,
  128,
  128,
  128,
  128,
  128,
  128,
  127,
  127,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  127,
  127,
  127,
  128,
  128,
  128,
  128,
  128,
  127,
  127,
  127,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  127,
  127,
  127,
  128,
  128,
  128,
  128,
  128,
  127,
  128,
  127,
  128,
  128,
  128,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  128,
  127,
  128,
  128,
  127,
  128,
  128,
  127,
  128,
  128,
  128,
  128,
  127,
  128,
  128,
  128,
  128,
  128,
  127,
  127,
  127,
  128,
  127,
  128,
  128,
  128,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  128,
  127,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  128,
  127,
  128,
  127,
  127,
  127,
  128,
  127,
  127,
  127,
  127,
  127,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  128,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  127,
  128,
  127,
  127,
  127,
  128,
  127,
  128,
  127,
};
LiquidCrystal lcd(12, 10, 5, 4, 3, 2);
const int switchPin = 6;
const int coinPin = 13;
int coinState = 0;
int prevCoinState = 0;
int switchState = 0;
int prevSwitchState = 0;
int reply;
void setup() {
  randomSeed(analogRead(0));
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  lcd.print("Ask the wondrous");
  lcd.setCursor(0, 1);
  lcd.print("Arabian Cat all!");
}
void loop() {
  coinState = digitalRead(coinPin);
  if (coinState != prevCoinState) {
    if (coinState == HIGH) {
      reply = random(40);
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("The cat is");
      lcd.setCursor(0, 1);
      lcd.print("thinking...");
      lcd.setCursor(0, 0);
      delay(1000);
      while (digitalRead(switchPin == HIGH)) {
        lcd.print("The cat has");
        lcd.setCursor(0, 1);
        lcd.print("His answer");
      }
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("The cat says");
      lcd.setCursor(0, 1);
      switch (reply) {
        case 0:
          lcd.print("Yes");
          break;
        case 1:
          lcd.print("No");
          break;
        case 2:
          lcd.print("Possibly");
          break;
        case 3:
          lcd.print("Probably");
          break;
        case 4:
          lcd.print("Probably not");
          break;
        case 5:
          lcd.print("meatball");
          break;
        case 6:
          lcd.print("IDK");
          break;
        case 7:
          lcd.print("You wish");
          break;
        case 8:
          lcd.print("I hope not");
          break;
        case 9:
          lcd.print("I hope so");
          break;
        case 10:
          lcd.print("Stinky Dinky");
          break;
        case 11:
          lcd.print("Leave at once");
          break;
        case 12:
          lcd.print("Indupitably");
          break;
        case 13:
          lcd.print("YOU???? HA HA!");
          break;
        case 14:
          lcd.print("Never");
          break;
        case 15:
          lcd.print("Next question");
          break;
        case 16:
          lcd.print("Get drip first");
          break;
        case 17:
          lcd.print("HAHAHAAAA");
          break;
        case 18:
          lcd.print("Unlikely");
          break;
        case 19:
          lcd.print("SPIRTE");
          break;
        case 20:
          lcd.print("Affirmative");
          break;
        case 21:
          lcd.print("Aight");
          break;
        case 22:
          lcd.print("Bet");
          break;
        case 23:
          lcd.print("Fo Shizzle");
          break;
        case 24:
          lcd.print("Yos");
          break;
        case 25:
          lcd.print("Ye Boae");
          break;
        case 26:
          lcd.print("You ain't French");
          break;
        case 27:
          lcd.print("Cringe");
          break;
        case 28:
          lcd.print("You will die");
          break;
        case 29:
          lcd.print("THE MUFFIN MAN?");
          break;
        case 30:
          lcd.print("Unfortunately");
          break;
        case 31:
          lcd.print("Nope");
          break;
        case 32:
          lcd.print("Go to college");
          break;
        case 33:
          lcd.print("UWU");
          break;
        case 34:
          lcd.print("Yes");
          break;
        case 35:
          lcd.print("No");
          break;
        case 36:
          lcd.print("Yes");
          break;
        case 37:
          lcd.print("No");
          break;
        case 38:
          lcd.print("Yes");
          break;
        case 39:
          lcd.print("Ratatouille");
          break;
      }
    }
  }
}
}
prevCoinState = coinState;
prevSwitchState = switchState;
}

I removed the majority of the frequencies, and it still gives me the error, I pasted it down below.

  1. go to your IDE
    press ctrl-t
    press shift-ctrl-c
  2. in a reply box here, press ctrl-v
    Look, you've just posted your code properly, instead of that hot mess you posted.

By the way, if you look at your code in the IDE after doing a ctrl-T, you'll find you actually have an extra couple of } at the end of loop().
You can find those by clicking on one - it's matching { will be hilighted, wherever it is.

Oh, and apologies for the terseness, I failed to note you're new here. Welcome!

Go here:

Note the top entries. Things like how to get along here, how to post code, how to post in this category are all explained.

}
}
} **// void loop() ends here, because you didn't match the pairs of curly braces**
}
prevCoinState = coinState;
prevSwitchState = switchState;
}

Thank you! I literally made an account to ask this question.

I'm really new to Arduino and I was trying to expand upon a project that came with the kit I bought, would I just move prevCoinstate = coinState; and prevSwitchState = switchState;
above that and delete the remaining brackets?

Please edit and fix your post #5. It is breaking forum rules. Please read the forum guide before posting again.

The IDE has Tools>AutoFormat on top.
Use that, or use the shortcut (post#7).

The IDE will tell you which closing bracket belongs to which opening bracket.
With text, and with a box around the other one.
Leo..

Thank you for your help.

@lachlisto You're welcome. And I apologize for those who repeat stuff you've already been told, they just don't read the whole thread sometimes.

Some people have to be told three times before the penny drops.
Some people ask twice because they don't want to hear how to fix it,
they just want you to fix it.
Leo..

Your array sample[] is not used in your code. I guess you added this for a new feature of the code? But the array did not cause the error, the error was there before. Is good to frequently check that your code contains no errors. You don't have to upload it to the Arduino to check for errors, just click the verify button. If you check for errors frequently, it's easier to figure out which change that your made is causing the error. Also use Auto Format frequently, as @Wawa suggests, this also helps greatly.

I also noticed that you used PROGMEM with the array. Perhaps you are concerned it will use too much memory? If you are concerned about memory use, there are many other lines in your code where you can make changes to save memory. For example all those strings like "You ain't French" will take up a lot of memory.

The sample[] array is a weird part of the PCM library, that I use to play audio because I don't have an SD card reader. I had no idea what PROGMEM did, although when the full list of frequencies is in it takes up around half of the built in storage anyways. The strings are supposed to be the answers to the crystal ball, so I can't really remove those. It's also really funny that you picked "You ain't French" as an example.

I wasn't suggesting that your remove them. Using PROGMEM and other similar techniques, you can avoid them taking up memory space.

But I was talking about RAM memory space, thinking that was your problem. Now I understand it is Flash memory space that could be the problem, and using PROGMEM etc. can't fix that.

Is it?

It's a shortened quote from the Soldier in Team Fortress 2. The full quote is "You ain't French, France isn't a country! Yer british!