Need Help Finding Error

Hi everyone!

i just need some help finding the error, really bugging me out rn XD

The error code is:
"Arduino: 1.8.10 (Windows 10), Board: "Arduino/Genuino Uno"

valueFunction:8:3: error: expected unqualified-id before 'for'

for(int x = 0; x < 300; x++)

^~~

valueFunction:8:18: error: 'x' does not name a type

for(int x = 0; x < 300; x++)

^

valueFunction:8:27: error: 'x' does not name a type

for(int x = 0; x < 300; x++)

^

valueFunction:23:2: error: expected ';' after class definition

}

^

;

valueFunction:30:3: error: expected unqualified-id before 'private'

private:

^~~~~~~

C:\Users\jacklythgoe\Documents\Training\Arduino Projects\Elegoo\FrequencyAndPressureOnLCD\FreqProjectv2\valueFunction\valueFunction.ino: In function 'int freqToLevelConv(float)':

valueFunction:41:28: error: 'freqInHz' was not declared in this scope

int high = (sizeof(freqInHz) / sizeof(freqInHz[0])) - 1;

^~~~~~~~

valueFunction:44:16: error: expected primary-expression before ')' token

while(low<=)

^

valueFunction:52:13: error: 'iround' was not declared in this scope

p = iround(p);

^~~~~~

C:\Users\jacklythgoe\Documents\Training\Arduino Projects\Elegoo\FrequencyAndPressureOnLCD\FreqProjectv2\valueFunction\valueFunction.ino:52:13: note: suggested alternative: 'round'

p = iround(p);

^~~~~~

round

valueFunction:62:13: error: expected '}' before 'else'

else if (x > freqInHz[mid])

^~~~

C:\Users\jacklythgoe\Documents\Training\Arduino Projects\Elegoo\FrequencyAndPressureOnLCD\FreqProjectv2\valueFunction\valueFunction.ino: At global scope:

valueFunction:74:5: error: expected declaration before '}' token

}

^

exit status 1
expected unqualified-id before 'for'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences."


int x;

class FreqToLevelConv
{
public:
int index = 0;

for(int x = 0; x < 300; x++)
{
index++;

double varToPower4 = x * x * x * x;
double varToPower3 = x * x * x;
double varToPower2 = x * x;
double varToPower1 = x;

freqInHz[index] = -(0.0000000001 * varToPower4) +
(0.0000000928 * varToPower3) -
(0.0000243704 * varToPower2) -
(0.0261888889 * varToPower1) +
44.6760000001;
}
}

int getLevel(float frequency)
{
return freqToLevelConv(frequency);
}

private:

float iround (float num)
{
return (((int)(num * 100 + .5) / 100.0));
}

int freqToLevelConv(float x)
{
float p;
int low = 0;
int high = (sizeof(freqInHz) / sizeof(freqInHz[0])) - 1;
int mid = 0;

while(low<=)
{
mid = (low+high)/2;

if (x < freqInHz[mid])
{
p = ((x - freqInHz[mid]) < 0) ? -(x - freqInHz[mid]) : (x - freqInHz[mid]);

p = iround(p);

if (p <= 0.059999999)
{
return mid;
}
else
{
high = mid - 1;
}
else if (x > freqInHz[mid])
{
low = mid + 1;
}
else
{
return mid;
}
}
return -1;

}
}
}

class FreqToLevelConv
{
  public:
  int index = 0;


  for(int x = 0; x < 300; x++)

The for loop is naked code - it has no place in a class.

Please remember to use code tags when posting code

Can you post your entire sketch?

I can't make sense of the code you posted. You have code outside of a function. Your braces don't match up. etc, etc.

Is this supposed to be a class definition?

Read the forum guidelines to see how to properly post code and error messages.

int x; // <<---


class FreqToLevelConv
{
  public:
  int index = 0;


  for(int x = 0; x < 300; x++) // <<---
  {
    index++;

might be x declared too much

rzk:
might be x declared too much

?

int x;
int freqInHz[10]; //you forgot to declare this array

class FreqToLevelConv
{
  public:
  int index = 0;

  int aloop()   //this for loop had to  context, so I put this in a funtion
  {
    
  for(int x = 0; x < 300; x++)
      {
        index++;
    
    
        double varToPower4 = x * x * x * x;
        double varToPower3 = x * x * x;
        double varToPower2 = x * x;
        double varToPower1 = x;
    
    
        freqInHz[index] = -(0.0000000001 * varToPower4) +
                           (0.0000000928 * varToPower3) -
                           (0.0000243704 * varToPower2) -
                           (0.0261888889 * varToPower1) +
                           44.6760000001;
      }
  }

  int getLevel(float frequency)
  {
    return freqToLevelConv(frequency);
  }


  private:


  float iround (float num)
  {
    return (((int)(num * 100 + .5) / 100.0));
  }


  int freqToLevelConv(float x)
  {
    float   p;
    int     low = 0;
    int     high = (sizeof(freqInHz) / sizeof(freqInHz[0])) - 1;
    int     mid = 0;


    while(low<=0) //you forgot to enter something here
    {
      mid = (low+high)/2;


      if (x < freqInHz[mid])
      {
        p = ((x - freqInHz[mid]) < 0) ? -(x - freqInHz[mid]) : (x - freqInHz[mid]);


        p = iround(p);


       if (p <= 0.059999999)
       {
          return mid;
       }
       else
       {
            high = mid - 1;
       } 
       
       if (x > freqInHz[mid])
       {
          low = mid + 1;
       }
       else
       {
           return mid;
       }
      }     
      return -1;
     
      }
    }
  
};
  • for loop had no context
  • you had a syntax error in your class
  • class name{}; instead of class name{}
  • your array was not declared in scope
  • you forgot something to compare your low value thing with

This can be compiled, but I'm pretty sure, it wont work