Forward was not declared in this scope

I have this code to spin a motor using a temperature sensor and reversing it with a pushbutton so I had different codes for each setup and I tried to join them and the setup together. I'm kind of a first timer with arduino

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*

  • setup() - this function runs once when you turn your Arduino on
  • We initialize the serial connection with the computer
    */
    //create 3 global variables
    //PWM controls speed
    //DIR A and B are the direction logic pins
    int PWM = 3;
    int DIRA = 4;
    int DIRB = 5;
    //create a global boolean variable to toggle
    //when button is pressed, set it to true.
    boolean state = true;
    void setup()
    {
    Serial.begin(9600); //Start the serial connection with the computer
    //to view the result open the serial monitor
    //pinModes for H-Bridge control pins
    pinMode(PWM,OUTPUT);
    pinMode(DIRA,OUTPUT);
    pinMode(DIRB,OUTPUT);
    //set pin 6 to INPUT_PULLUP, no need for a pullup resistor
    pinMode(6,INPUT_PULLUP);
    }

void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);

// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;

// print out the voltage
Serial.print(voltage); Serial.println(" volts");

// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");

if(temperatureC > 12){
analogWrite(9, 250);
}
{
//create a local varaible thats stores the button state (1 or 0)
int buttonState = digitalRead(6);

//if buttonState is 0 (less than 1) toggle the state variable to
//the opposite of the current state (!state)
if(buttonState < 1)
{
state = !state;
delay(250);
}

//if state is false drive motor forward, else stop.
if(state == false)
{
forward(250);
}
else
{
brake();
}
}

//custom function for forward
void forward(int Speed)
{
digitalWrite(DIRA,250);
digitalWrite(DIRB,0);
analogWrite(PWM,Speed);
}

//custom function for reverse
void reverse(int Speed)
{
digitalWrite(DIRA,0);
digitalWrite(DIRB,250);
analogWrite(PWM,Speed);
}

//custom function for brake (stop)
void brake()
{
digitalWrite(DIRA,0);
digitalWrite(DIRB,0);
}

delay(1000); //waiting a second
}

Please post your code using </>

You've declared your functions, forward()' etc, inside 'loop()'. Once they're moved outside the 'loop()' function, it compiles fine:-

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures

/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
//create 3 global variables
//PWM controls speed
//DIR A and B are the direction logic pins
int PWM = 3;
int DIRA = 4;
int DIRB = 5;
//create a global boolean variable to toggle
//when button is pressed, set it to true.
boolean state = true;

void setup()
{
    Serial.begin(9600);  //Start the serial connection with the computer
    //to view the result open the serial monitor
    //pinModes for H-Bridge control pins
    pinMode(PWM, OUTPUT);
    pinMode(DIRA, OUTPUT);
    pinMode(DIRB, OUTPUT);
    //set pin 6 to INPUT_PULLUP, no need for a pullup resistor
    pinMode(6, INPUT_PULLUP);
}

void loop()                     // run over and over again
{
    //getting the voltage reading from the temperature sensor
    int reading = analogRead(sensorPin);

    // converting that reading to voltage, for 3.3v arduino use 3.3
    float voltage = reading * 5.0;
    voltage /= 1024.0;

    // print out the voltage
    Serial.print(voltage); Serial.println(" volts");

    // now print out the temperature
    float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
    //to degrees ((voltage - 500mV) times 100)
    Serial.print(temperatureC); Serial.println(" degrees C");

    if (temperatureC > 12)
    {
        analogWrite(9, 250);
    }
    {
        //create a local varaible thats stores the button state (1 or 0)
        int buttonState = digitalRead(6);

        //if buttonState is 0 (less than 1) toggle the state variable to
        //the opposite of the current state (!state)
        if (buttonState < 1)
        {
            state = !state;
            delay(250);
        }

        //if state is false drive motor forward, else stop.
        if (state == false)
        {
            forward(250);
        }
        else
        {
            brake();
        }
    }
    delay(1000);                                     //waiting a second
}

//custom function for forward
void forward(int Speed)
{
    digitalWrite(DIRA, 250);
    digitalWrite(DIRB, 0);
    analogWrite(PWM, Speed);
}

//custom function for reverse
void reverse(int Speed)
{
    digitalWrite(DIRA, 0);
    digitalWrite(DIRB, 250);
    analogWrite(PWM, Speed);
}

//custom function for brake (stop)
void brake()
{
    digitalWrite(DIRA, 0);
    digitalWrite(DIRB, 0);
}

Disclaimer: I didn't look further to see if it would work though.
Edit: There are brackets around another section of your code for an unknown reason - I'm not sure what's going on there.
And as ieee488 says, please edit and place your code between code tags.

  digitalWrite(DIRA,250);

Uuuhh?

digitalWrite(DIRA,250);

AWOL:
Uuuhh?

He/she wants it real high. :smiley:

Glad I said this:-

Disclaimer: I didn't look further.......

(Still don't know how I overlooked something sooo obvious. :frowning: )