return-statement with a value, in function returning 'void' [-fpermissive]

Hello!
this is my first problem i could not get rid of browsing this forum...(I am still a newbie...)

i have a program consisting out of 3 other program parts which all function perfectly alone (hard and software)

but now when i merge them alltogether in one- i am getting an error message about the return value of my rotary encoder readout function. i do not understand where this error is coming from. because the function workd perfectly in the smaller program. so i guess it cant be something about the value/data type of the function because i added only some lines in the setup part and some in the loop part which are not having any interaction nor using the same variables/constants/pins...

this is the function i am using: (a rotary encoder to set a value by turning the nob)

//function returns change in encoder state (-1,0,1)
int read_encoder();
{
static int8_t enc_states[] = {0, -1, 1,0, 1,0,0, -1, -1,0,0, 1,0, 1, -1,0};
static uint8_t old_AB = 0;
old_AB <<= 2; //remember previous state
old_AB |= ( ENC_PORT & 0x03 ); //add current state
return ( enc_states[( old_AB & 0x0f )]); this is the line error line
}

error messages

Arduino: 1.6.5 (Windows 7), Platine: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

meter_v2.ino: In function 'void loop()':
meter_v2:95: error: return-statement with a value, in function returning 'void' [-fpermissive]
return-statement with a value, in function returning 'void' [-fpermissive]

anyone has a clue what is wrong with the function?

thanks a lot for your help!
i think a am facing a pretty simple problem of the return function i am not even aware of...

best regards
martin

Read the "how to use the forum" stickies to see how to format and post code. Post all of your code. Post the entire error message.

... and use code tags for each!

The error message says that the problem is in loop(). Why do you think that the problem is in read_encoder() ?

Hello!
sorry for the unformatted first post...first had to be pushed to read about how to post code...

i guess the error is in the function because in the error report lines there is written that there (i guess) a problem with the return value/format of my function.... i guess i have done something wrong with declaring the return value of the function...

i hope you get along with the code despite there is german mixed in to comment the code...

thanks a lot!

//Rotary encoder 

      #define ENC_A 14
      #define ENC_B 15
      #define ENC_PORT PINC
      float benzin; //this variable will be changed by encoder input
      float fuel= 0;
      float zaehler = 0;
      int set = 0; // soetwas nennt man auch "Merker"
      int read_encoder();
//flowmeter
      #include "LiquidCrystal.h"
      LiquidCrystal lcd(7, 8, 9, 12, 11, 10);
      
      // which pin to use for reading the sensor? can use any pin!
      #define FLOWSENSORPIN 2
      
      // count how many pulses!
      volatile uint16_t pulses = 0;
      // track the state of the pulse pin
      volatile uint8_t lastflowpinstate;
      // you can try to keep time of how long it is between pulses
      volatile uint32_t lastflowratetimer = 0;
      // and use that to calculate a flow rate
      volatile float flowrate;
      // Interrupt is called once a millisecond, looks for any pulses from the sensor!

//switch
      const int buttonPin = 4;     // the number of the pushbutton pin
      const int ledPin =  5;      // the number of the LED pin
      
      // variables will change:
      int buttonState = 0;         // variable for reading the pushbutton status

 
void setup()
{
// rotary encoder variables Setup encoder pins as inputs */
      pinMode(ENC_A, INPUT);
      digitalWrite(ENC_A, HIGH);
      pinMode(ENC_B, INPUT);
      digitalWrite(ENC_B, HIGH);
      Serial.begin (115200);
      Serial.println("Start");
      //float tmpdata;
      float benzin = 0;
      float fuel;
 
// flowsensor variables
      Serial.print("Flow sensor test!");
      lcd.begin(16, 2);
      pinMode(FLOWSENSORPIN, INPUT);
      digitalWrite(FLOWSENSORPIN, HIGH);
      lastflowpinstate = digitalRead(FLOWSENSORPIN);
      boolean useInterrupt(true);
   
// button variables
      // initialize the LED pin as an output:
      pinMode(ledPin, OUTPUT);
      // initialize the pushbutton pin as an input:
      pinMode(buttonPin, INPUT);   
}

void loop()  
{
  /////////////////status switch//////////////////////
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);// check if the pushbutton is pressed. if it is, the buttonState is HIGH:
  if (buttonState == HIGH) 
  {
    digitalWrite(ledPin, HIGH);// turn LED on:
    // bei gedrücktem button anzeige mit rotary encoder erhöhen wenn rotary gedreht wird
  ///////rotary encoder///////////////////////////////////////////////////////
         //static uint8_t benzin = 0;      //this variable will be changed by encoder input
         float tmpdata;
         //float read_encoder();
         
          tmpdata = read_encoder();
          if( tmpdata ) 
            {
              Serial.print("Benzin: ");
              Serial.println(fuel);
              benzin += tmpdata;
              benzin = constrain(benzin,0,150);// 150 entspricht 15 litern tankinhalt
              fuel = benzin/10; 
            }
         
          //function    returns change in encoder state (-1,0,1)
           int read_encoder();
          {
          static int8_t enc_states[] = {0,  -1,  1,0,  1,0,0,  -1,  -1,0,0,  1,0,  1,  -1,0};
          static uint8_t old_AB = 0;
          old_AB <<= 2;                   //remember previous state
          old_AB |= ( ENC_PORT & 0x03 );  //add current state
          return ( enc_states[( old_AB & 0x0f )]);
          }
       
  }
  else 
  {
              // turn LED off:
              digitalWrite(ledPin, LOW);
             // wenn button losgelassen nehme fuel und substrahiere permanent den verbrauch 
    ////////// flowmeter   /////////////////////////////////                
              lcd.setCursor(0, 0);
              lcd.print("Pu:"); lcd.print(pulses, DEC);
              lcd.print(" l/h:"); lcd.print(flowrate);
              Serial.print("Freq: "); Serial.println(flowrate);
              Serial.print("Pulses: "); Serial.println(pulses);
              float fuel = pulses;
              fuel /= 1920;
              //liters = 15-liters;
              flowrate = flowrate*0,5194;
              //liters /= 60.0;
              Serial.print(fuel); Serial.println("l Benzin");
              lcd.setCursor(0, 1);
              lcd.print(fuel); lcd.print(" l Benzin");
             
              delay(1000);
  }
}

these are the error lines

fuel_meter_v2.ino: In function 'void loop()':
fuel_meter_v2.ino:95:49: error: return-statement with a value, in function returning 'void' [-fpermissive]
return-statement with a value, in function returning 'void' [-fpermissive]
int read_encoder();

That is a function definition inside another function (loop()). You cannot have a function definition inside another function. Move the function out of loop(). Remove the semicolon from the end.

int read_encoder()
    {
      static int8_t enc_states[] = {0,  -1,  1, 0,  1, 0, 0,  -1,  -1, 0, 0,  1, 0,  1,  -1, 0};
      static uint8_t old_AB = 0;
      old_AB <<= 2;                   //remember previous state
      old_AB |= ( ENC_PORT & 0x03 );  //add current state
      return ( enc_states[( old_AB & 0x0f )]);
    }

Then you can call the function with the existing:

tmpdata = read_encoder();

This compiles but is untested:

//Rotary encoder

#define ENC_A 14
#define ENC_B 15
#define ENC_PORT PINC
float benzin; //this variable will be changed by encoder input
float fuel = 0;
float zaehler = 0;
int set = 0; // soetwas nennt man auch "Merker"
int read_encoder();
//flowmeter
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 12, 11, 10);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!

//switch
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  5;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status


void setup()
{
  // rotary encoder variables Setup encoder pins as inputs */
  pinMode(ENC_A, INPUT);
  digitalWrite(ENC_A, HIGH);
  pinMode(ENC_B, INPUT);
  digitalWrite(ENC_B, HIGH);
  Serial.begin (115200);
  Serial.println("Start");
  //float tmpdata;
  float benzin = 0;
  float fuel;

  // flowsensor variables
  Serial.print("Flow sensor test!");
  lcd.begin(16, 2);
  pinMode(FLOWSENSORPIN, INPUT);
  digitalWrite(FLOWSENSORPIN, HIGH);
  lastflowpinstate = digitalRead(FLOWSENSORPIN);
  boolean useInterrupt(true);

  // button variables
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop()
{
  /////////////////status switch//////////////////////
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);// check if the pushbutton is pressed. if it is, the buttonState is HIGH:
  if (buttonState == HIGH)
  {
    digitalWrite(ledPin, HIGH);// turn LED on:
    // bei gedrücktem button anzeige mit rotary encoder erhöhen wenn rotary gedreht wird
    ///////rotary encoder///////////////////////////////////////////////////////
    //static uint8_t benzin = 0;      //this variable will be changed by encoder input
    float tmpdata;
    //float read_encoder();

    tmpdata = read_encoder();
    if ( tmpdata )
    {
      Serial.print("Benzin: ");
      Serial.println(fuel);
      benzin += tmpdata;
      benzin = constrain(benzin, 0, 150); // 150 entspricht 15 litern tankinhalt
      fuel = benzin / 10;
    }

    //function    returns change in encoder state (-1,0,1)
    int encoderValue = read_encoder();

  }
  else
  {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    // wenn button losgelassen nehme fuel und substrahiere permanent den verbrauch
    ////////// flowmeter   /////////////////////////////////
    lcd.setCursor(0, 0);
    lcd.print("Pu:"); lcd.print(pulses, DEC);
    lcd.print(" l/h:"); lcd.print(flowrate);
    Serial.print("Freq: "); Serial.println(flowrate);
    Serial.print("Pulses: "); Serial.println(pulses);
    float fuel = pulses;
    fuel /= 1920;
    //liters = 15-liters;
    flowrate = flowrate * 0, 5194;
    //liters /= 60.0;
    Serial.print(fuel); Serial.println("l Benzin");
    lcd.setCursor(0, 1);
    lcd.print(fuel); lcd.print(" l Benzin");

    delay(1000);
  }
}

int read_encoder()
    {
      static int8_t enc_states[] = {0,  -1,  1, 0,  1, 0, 0,  -1,  -1, 0, 0,  1, 0,  1,  -1, 0};
      static uint8_t old_AB = 0;
      old_AB <<= 2;                   //remember previous state
      old_AB |= ( ENC_PORT & 0x03 );  //add current state
      return ( enc_states[( old_AB & 0x0f )]);
    }