second set of eyes please, error code, functions not declared.

if someone could take a look and see why I’m getting the error code. I’ve looked for all the correct “{}” and tried moving my functions around and putting the function names in the globals. I really don’t know what else to look for.
My coding skills still need practice.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

long randomNumber;
int randomA;
int randomB;
int randomC;
int randomD;
int randomCode;
int codeVal;

int realNumber;
int realA;
int realB;
int realC;
int realD;

int value;
int count;
int state;
int lastState;
int counter;

int relayPin = 5;
int SW = 2;
int CLK = 9;  // Pin 9 to clk on encoder
int DT = 8;  // Pin 8 to DT on encoder

void setup() {
  
  lcd.begin(16, 2);
  randomSeed(analogRead(0));
  pinMode (SW, INPUT);
  pinMode (CLK, INPUT);
  pinMode (DT, INPUT);
  pinMode  (relayPin, OUTPUT);
  counter = 5;
  count = 0;
  lastState = digitalRead(CLK);
}

void loop() {

  lcd.setCursor(0, 0);
  lcd.print("  Code  #");
  lcd.setCursor(0, 1);
  lcd.print(" Access #");
  lcd.setCursor(11, 0);
  lcd.print(randomCode);
  
  if (count == 0){
    randomGen();
  }

  if (digitalRead(SW) == HIGH) {
    delay(500);
    count++;
  }
  switch (count) {  //RotPosition = counter
    case 1:
      select();
      realA = (counter * 1000);
      lcd.setCursor(11, 1);
      lcd.print(counter);
      break;
    case 2:
      lcd.setCursor(11, 1);
      lcd.print("*");
      select();
      realB = (counter * 100);
      lcd.setCursor(12, 1);
      lcd.print(counter);
      break;
    case 3:
      lcd.setCursor(12, 1);
      lcd.print("*");
      select();
      realC = (counter * 10);
      lcd.setCursor(13, 1);
      lcd.print(counter);
      break;
    case 4:
      lcd.setCursor(13, 1);
      lcd.print("*");
      select();
      realD = (counter * 10);
      lcd.setCursor(14, 1);
      lcd.print(counter);
      break;
    case 5:
      lcd.setCursor(14, 1);
      lcd.print("*");
      delay(500);
      check();
      break;
  }
}

int select() {
  state = digitalRead(CLK);
  if (state != lastState) {
    if (digitalRead(DT) != state) {
      counter++;
    }
    else {
      counter--;
    }
  }
    if (digitalRead(SW) == HIGH) {
    delay(500);
    count++;
  }
}

int check() {
  realNumber = (realA + realB + realC + realD);
  codeVal = map (randomCode, 9999, 1111, 1111, 9999);

  if (codeVal == realNumber) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("    * ACCESS    ");
    lcd.setCursor(0,1);
    lcd.print("     GRANTED    ");
    delay(500);
    digitalWrite(relayPin, HIGH);
    delay(3000);
    digitalWrite(relayPin, LOW);
    count = 0;
    counter = 5;
    lcd.clear();
  }
    if (codeVal != realNumber) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("     ACCESS     ");
    lcd.setCursor(0,1);
    lcd.print("     DENIED     ");
    delay(3000);
    count = 0;
    counter = 5;
    lcd.clear();
}

int randomGen() {
  randomNumber = random(1, 10);
  randomA = (randomNumber * 1000);
  randomB = (randomNumber * 100);
  randomC = (randomNumber * 10);
  randomD = randomNumber;
  randomCode = (randomA + randomB + randomC + randomD);
  delay(100);
    if (digitalRead(SW) == HIGH) {
    delay(500);
    count++;
  }
  return randomCode;
}

LandonW:
if someone could take a look and see why I'm getting the error code.

It would be very helpful if you specified what "the error code" is. In fact, copy and post the complete error message(s) verbatim.

LandonW:
I’ve looked for all the correct “{}”

Auto format your code (ctrl-t) and look again. Remember, you’re not allowed to define functions within functions.

It would be very helpful if you specified what “the error code” is. In fact, copy and post the complete error message(s) verbatim.
[/quote]

Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: “Arduino Pro or Pro Mini, ATmega328P (5V, 16 MHz)”

C:\Users\Landon\Documents\Arduino\Random_Code_Safe\Random_Code_Safe.ino: In function ‘void loop()’:

Random_Code_Safe:53: error: ‘randomGen’ was not declared in this scope

randomGen();

^

C:\Users\Landon\Documents\Arduino\Random_Code_Safe\Random_Code_Safe.ino: In function ‘int check()’:

Random_Code_Safe:146: error: a function-definition is not allowed here before ‘{’ token

int randomGen() {

^

Random_Code_Safe:159: error: expected ‘}’ at end of input

}

^

exit status 1
‘randomGen’ was not declared in this scope

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

See Reply #2.

Something that I found helpful when learing to code in C++ is to put every { and every } on their own lines. It is easier to see if the brackets are matched, especially in combination with autoformat.

if(something == somethingElse)
  {
      // do this
  }
  else
  {
      // do that
  }

I auto format every 5 to 10 lines...

but I guess a } was missing on line 145.

Thanks, sometimes I feel like it a Where's Waldo in a 3D image book lol