break statement not within loop or switch

Hey guys, I’m making using a soil moisture sensor with an Arduino. There is an error statement that keeps coming which says that the break statement is not within the lop or switch. I don’t know why it says that since I put the break in a switch statement. Here is the code (the break statement is at the very bottom):
#include <LCD5110_Graph.h>

LCD5110 lcd(8,9,10,12,11);

int sensorPin = A0;
int sensorValue = 0;
int percent = 0;
String percentString =“0”;
int stringLength = 0;

extern unsigned char BigNumbers;
extern uint8_t ui;

int OtherSensorPin = A1;
int OtherSensorValue = 0;
int OtherPercent = 0;
String OtherPercentString = “0”;
int OtherStringLength = 0;

void setup() {
lcd.InitLCD();
lcd.setFont(BigNumbers);
delay(1000);
}

void loop() {
lcd.clrScr();
lcd.drawBitmap(0, 0, ui, 84, 48);
OtherSensorValue = analogRead(OtherSensorPin);
OtherPercent = OtherSensorValue;
OtherPercentString = String(OtherPercent);
OtherStringLength = OtherPercentString.length();

lcd.update();
delay(1000);
}

int convertToPercent(int value)
{
int OtherPercentValue = 0;
OtherPercentValue = map(OtherSensorValue, 1023, 350, 0, 100);
if(OtherPercentValue>100)
OtherPercentValue = 100;
return OtherPercentValue;

int percentValue = 0;
percentValue = map(sensorValue, 1023, 350, 0, 100);
if(percentValue>100)
percentValue = 100;
return percentValue;
}

void displayPercent(int length)
{
switch(length)

case 1: lcd.print(percentString,38,19); break;
case 2: lcd.print(percentString,24,19); break;
case 3: lcd.print(percentString,10,19); break;
default:lcd.print(percentString,0,19); break;
}

You should read the locked topics at the head of this forum so that you may post code properly.

Your switch statement is incorrect because it is missing the curly brackets. You have

 switch(length)
   
    case 1: lcd.print(percentString,38,19); break;
    case 2: lcd.print(percentString,24,19); break;
    case 3: lcd.print(percentString,10,19); break;
    default:lcd.print(percentString,0,19); break;

but it should look more like (untested)

 switch(length)
{
   
    case 1: lcd.print(percentString,38,19); break;
    case 2: lcd.print(percentString,24,19); break;
    case 3: lcd.print(percentString,10,19); break;
    default:lcd.print(percentString,0,19); break;
}

The compiler was correct when it told you that the break statement was not in a switch statement.

oh lol ok thank you very much!

int convertToPercent(int value)
 {
  int OtherPercentValue = 0;
  OtherPercentValue = map(OtherSensorValue, 1023, 350, 0, 100);
  if(OtherPercentValue>100)
    OtherPercentValue = 100;
  return OtherPercentValue;
  
  int percentValue = 0;
  percentValue = map(sensorValue, 1023, 350, 0, 100);
  if(percentValue>100)
    percentValue = 100;
  return percentValue;
 }

All the code after the first return statement is useless.

sensorValue and OtherSensorValue are dumb names. You did not grab a catalog, look up sensor in the index, and order a random undefined sensor. You have a sensor that senses something VERY specific. The names should reflect that.

If you have two of the same kind of sensor, then the names should reflect the reason that there are two of them, like an indoor temperature sensor and an outdoor temperature sensor.