problem with combining code

Hi i got some trouble with my code here’s my code

#include <Servo.h>

int enablePin = 11;

int in1Pin = 10;

int in2Pin = 9;

int switchPin = 7;

int potPin = 0;

int statusPin= 13;

const int buttonPin = 2;

const int buttonPin2 = 4;

int buttonState = 0;

int buttonState2 = 0;

Servo servoA;

int position = 0;

void setup() {

servoA.attach(9);

pinMode(buttonPin, INPUT);

pinMode(buttonPin2,INPUT);

pinMode(in1Pin, OUTPUT);

pinMode(in2Pin, OUTPUT);

pinMode(enablePin, OUTPUT);

pinMode(switchPin, INPUT_PULLUP);

pinMode(statusPin,OUTPUT);
}

void loop() {

buttonState = digitalRead(buttonPin);

buttonState2 = digitalRead(buttonPin2);

if(buttonState ==HIGH && position < 180){

servoA.write(position++);

delay(5);

digitalWrite(13,HIGH);

int speed = analogRead(potPin) / 4;

boolean reverse = digitalRead(switchPin);

setMotor(speed, reverse);

void setMotor(int speed, boolean reverse)

{

analogWrite(enablePin, speed);

digitalWrite(in1Pin, ! reverse);

digitalWrite(in2Pin, reverse);

}
}

if(buttonState2 == HIGH && position > 3){

servoA.write(position–);

delay(5);

}

}

and the error log I get is

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

Why is it displaying an error message and how can I fix it.

Check } braces. Use code tags. Floss regularly

I changed some of the code and don’t get that error message anymore now I get this error massage instead

Arduino: 1.8.1 (Windows Store 1.8.1.0) (Windows 10), Board: “Arduino/Genuino Uno”

servo.ino:60: error: expected unqualified-id before ‘if’

if(buttonState ==HIGH && position < 180){

^

servo.ino:68: error: expected unqualified-id before ‘if’

if(buttonState2 == HIGH && position > 3){

^

exit status 1
expected unqualified-id before ‘if’

and this is the code

#include <Servo.h>

int enablePin = 11;

int in1Pin = 10;

int in2Pin = 9;

int switchPin = 7;

int potPin = 0;

int statusPin= 13;

const int buttonPin = 2;

const int buttonPin2 = 4;

int buttonState = 0;

int buttonState2 = 0;

Servo servoA;

int position = 0;

void setup() {

servoA.attach(9);

pinMode(buttonPin, INPUT);

pinMode(buttonPin2,INPUT);

pinMode(in1Pin, OUTPUT);

pinMode(in2Pin, OUTPUT);

pinMode(enablePin, OUTPUT);

pinMode(switchPin, INPUT_PULLUP);

pinMode(statusPin,OUTPUT);
}

void loop() {

buttonState = digitalRead(buttonPin);

buttonState2 = digitalRead(buttonPin2);
digitalWrite(13,HIGH);

int speed = analogRead(potPin) / 4;

boolean reverse = digitalRead(switchPin);

setMotor(speed, reverse);

}
if(buttonState ==HIGH && position < 180){

servoA.write(position++);

delay(5);

}

if(buttonState2 == HIGH && position > 3){

servoA.write(position–);

delay(5);

}
void setMotor(int speed, boolean reverse)

{

analogWrite(enablePin, speed);

digitalWrite(in1Pin, ! reverse);

digitalWrite(in2Pin, reverse);
}

void loop() {

buttonState = digitalRead(buttonPin);

buttonState2 = digitalRead(buttonPin2);
  digitalWrite(13,HIGH);

int speed = analogRead(potPin) / 4;

boolean reverse = digitalRead(switchPin);

setMotor(speed, reverse);

}

See reply #1