String to integer problems

Hi, I'm trying to get it so that when my string named actualcycles is the same as my integer displaycycles a message pops up. However im getting error messages that are saying that it can't convert string to integer. Any help would be greatly appreciated I'm a newby :).

/*****************************************
   name: I2C LCD2004
   function: You should now see your I2C LCD2004 display "Hello,world!","IIC/I2C LCD2004"
   "20 cols, 4 rows","www.sunfounder.com"
 ********************************/
//Email:service@sunfounder.com
//Website:www.sunfounder.com

/********************************/
// include the library code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display

const int buttonPin1 = 11;     // the number of the pushbutton pin
const int buttonPin2 = 10;
const int buttonPin3 = 9;
const int buttonPin4 = 8;

int screen_flag = 1;

int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

int force = 1000;
int cycles = 1;
int ForceN = 0;
int actualcycles = 0;

/*********************************************************/
void setup()
{
  lcd.init();  //initialize the lcd
  lcd.backlight();  //open the backlight

  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
}
/*********************************************************/
void loop()
{
  lcd.clear();
  lcd.setCursor ( 0, 0 );            // go to the top left corner
  lcd.print("===================="); // write this string on the top row
  lcd.setCursor ( 2, 1 );            // go to the top left corner
  lcd.print("-=Torsion  Rig=-"); // write this string on the top row
  lcd.setCursor ( 0, 3 );            // go to the top left corner
  lcd.print("===================="); // write this string on the top row
  delay(3000);
  /*********************************************************/
  delay(100);
  lcd.clear();
  buttonState1 = digitalRead(buttonPin1);
  screen_flag = 1;

  while (buttonState1 == LOW) {
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    buttonState4 = digitalRead(buttonPin4);
    if (buttonState3 == HIGH) {
      force = force + 1;
      screen_flag = 1;
      delay(50);
    }

    if (buttonState4 == HIGH) {
      force = force - 1;
      screen_flag = 1;
      delay(50);
    }

    if (force <= 100) {
      force = 100;
    }

    if (force >= 4000) {
      force = 4000;
    }

    String displayforce = String(force);
    int len2 = displayforce.length() + 1;

    if (screen_flag == 1) {
      lcd.clear();
      lcd.setCursor ( 0, 0 );            // go to the top left corner
      lcd.print("Select Force"); // write this string on the top row
      lcd.setCursor ( 0, 1 );            // go to the top left corner
      lcd.print("(Newtons)"); // write this string on the top row
      lcd.setCursor ( 10, 2 );            // go to the top left corner
      lcd.print(displayforce); // write this string on the top row
      screen_flag = 0;
    }
    delay(50);
  }


  /************************************************************/
  delay(150);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  screen_flag = 1;
  lcd.clear();
  delay(100);
  while (buttonState1 == LOW) {
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    buttonState4 = digitalRead(buttonPin4);

    if (buttonState3 == HIGH) {
      cycles = cycles + 1;
      screen_flag = 1;
      delay(50);
    }

    if (buttonState4 == HIGH) {
      cycles = cycles - 1;
      screen_flag = 1;
      delay(50);
    }

    if (cycles <= 1) {
      cycles = 1;
    }
    if (cycles >= 10) {
      cycles = 10;
    }

    String displaycycles = String(cycles);
    int len2 = displaycycles.length() + 1;

    if (screen_flag == 1) {
      lcd.clear();
      lcd.setCursor ( 0, 0 );            // go to the top left corner
      lcd.print("Select Num Cycles"); // write this string on the top row
      lcd.setCursor ( 0, 1 );            // go to the top left corner
      lcd.print("(Each Way)"); // write this string on the top row
      lcd.setCursor ( 10, 2 );            // go to the top left corner
      lcd.print(displaycycles); // write this string on the top row
      screen_flag = 0;
    }
    delay(50);
  }
  /************************************************************/
  delay(150);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  screen_flag = 1;
  lcd.clear();
  delay(100);
  while (buttonState2 == LOW) {
    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    buttonState4 = digitalRead(buttonPin4);

    if (screen_flag == 1) {
      lcd.clear();
      lcd.setCursor ( 0, 0 );            // go to the top left corner
      lcd.print("Press Select To Edit"); // write this string on the top row
      lcd.setCursor ( 0, 2 );            // go to the top left corner
      lcd.print("Press Scroll To Run"); // write this string on the top row
      screen_flag = 0;
      }
      if (buttonState1 == HIGH) {
        return;
    }
    delay(50);
  }
  /************************************************************/
  delay(150);
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  actualcycles = 0;
  screen_flag = 1;
  lcd.clear();
  delay(100);

  while (buttonState2 == LOW) {

    buttonState1 = digitalRead(buttonPin1);
    buttonState2 = digitalRead(buttonPin2);
    buttonState3 = digitalRead(buttonPin3);
    buttonState4 = digitalRead(buttonPin4);
    //==========================================
    //-=(Run Code)=-
    if (ForceN <= force) {
      actualcycles = actualcycles + 1;
      screen_flag = 1;
      delay(50);
    }

    if (ForceN <= force - force * 2 ) {
      actualcycles = actualcycles + 1;
      screen_flag = 1;
      delay(50);
      String displaycycles = String(displaycycles);
      int len2 = displaycycles.length() + 1;
    }
    //==========================================
     delay(150);
    if (screen_flag == 1) {
       String displaycycles = String(cycles);
      lcd.clear();
      lcd.setCursor ( 0, 0 );            // go to the top left corner
      lcd.print("Running"); // write this string on the top row
      lcd.setCursor ( 0, 1 );            // go to the top left corner
      lcd.print("Please Wait"); // write this string on the top row
      lcd.setCursor ( 0, 2 );            // go to the top left corner
      lcd.print("Cycles Done:"); // write this string on the top row
      lcd.setCursor ( 12, 2 );            // go to the top left corner
      lcd.print(actualcycles); // write this string on the top row
      screen_flag = 0;
      lcd.setCursor ( 0, 3 );
      lcd.print("Cycles To Do:"); // write this string on the top row
      lcd.print(displaycycles);



      if (actualcycles = displaycycles) {
         
      lcd.clear();
      lcd.setCursor ( 0, 0 );          
      lcd.print("Cycles Completed");
      delay(150);
    }
    }
  
    delay(50);
  }
  /************************************************************/

}

Why are you using a String data type for displaycycles ?
Come to that why do you need that variable ?

First of all, this test is not correct:

if (actualcycles = displaycycles)

Then actualcycles is an integer, and displaycycles a String. You have to use the toInt method of the String class:

if (actualcycles == displaycycles.toInt())

That worked perfectly. I tried that earlier but didn't present it the same way. Thank you :slight_smile:

That worked perfectly. I tried that earlier but didn't present it the same way. Thank you :slight_smile:

So good you posted it twice :slight_smile:

What is the purpose of the displaycycles String object ? Why isn't it an integer ?

You do not have to convert an int to a String in order to display it. The .print() function does the conversion to text.