Button to change display not working

I just received an Arduino for Christmas and I am trying to get make a little program when a button is pushed that the LCD display will change from showing Celsius to Fahrenheit and back. However, when the button is pressed the LCD screen shows circles across the top row.

The program worked fine when all it was doing was showing the temperature and humidity without trying to change the format of the temperature.

All I am using is a DHT11 and a 16x2 LCD with a simple push-button connected.

#include <LiquidCrystal.h>
#include <DHT.h>
#define DHT11_PIN 2
DHT dht(DHT11_PIN, DHT11);

LiquidCrystal lcd(13,12,4,5,6,7);

float temperature;

const int buttonPin = 10;
int displayNumber = 1;

void setup() {
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  float humidity = dht.readHumidity();
  temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
      Serial.println("Failed to read from DHT sensor!");
      return;
    }

if(displayNumber == 1){
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(tempCelsius(temperature));
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(humidity);
  lcd.print("%");
  delay(1000);
}
else if(displayNumber == 2){
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(temp(temperature));
  lcd.print((char)223);
  lcd.print("F");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(humidity);
  lcd.print("%");
  delay(1000);
}

if(digitalRead(buttonPin) == HIGH){
  displayNumber = displayNumber + 1;
     if (displayNumber > 2){
      displayNumber = 1;
     }
  
}
delay(2000);
}

float temp(float){

  float tempF = temperature * 9 / 5 +32;
  return tempF;
  
}

float tempCelsius(float){
  
  float tempC = (temp(temperature)-32) * 5 / 9;
  return tempC;
}

One debugging technique is to go back to code that worked and then make incremental changes until it doesn't work. That should help you pinpoint the problem. Give that a try.

Also, here's a problem that may or may not be related to your symptoms:

float temp(float)

The problem is that you have not included a parameter after the "float" inside the parentheses after the function name. This page will help you understand function parameters: Arduino - FunctionDeclaration Your tempCelsius function has the same problem.

But, since "temperature" is a global variable, in fact there is no need to pass it to the functions, so the parentheses could be/should be completely empty. This page will help you understand even more about variable "scope" and function parameters: http://forum.arduino.cc/index.php?topic=383064.0

And, since the DHT returns Celsius temperature as default, there is no need for a tempCelsius function.

Furthermore, your two-second delay will render your button not very responsive. Suggest revising your program using the "blink without delay" technique (google it) to refresh the LCD every "x" seconds (and on button push) and allow "loop" to check button status without delay. (Do this after you get everything else working.)

Thanks for the help with cleaning up my code.

I decided to try this in a serial monitor and it works.
This is what it gives:
Temp: 26.00⸮C
Humidity: 42.00%
Temp: 26.00⸮C
Humidity: 42.00%
Failed to read from DHT sensor! → when I push the button
Temp: 0.00⸮C
Humidity: 0.00%
Temp: 32.00⸮F
Humidity: 0.00%
Temp: 78.80⸮F
Humidity: 42.00%

This switches back and forth like I want it to, though when I tried my code(which is nearly identical to the serial monitor code I have) the LCD shows something thing along the line of this:
0 <-o°o o0o <-0<-

code that I am now using:

#include <LiquidCrystal.h>
#include <DHT.h>
#define DHT11_PIN 2
DHT dht(DHT11_PIN, DHT11);

LiquidCrystal lcd(13,12,4,5,6,7);

float temperature;

const int buttonPin = 10;
int displayNumber = 1;

void setup() {
  lcd.begin(16, 2);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  float humidity = dht.readHumidity();
  temperature = dht.readTemperature();

  if (isnan(humidity) || isnan(temperature)) {
    lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Failed");
      return;
    }

if(displayNumber == 1){
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(humidity);
  lcd.print("%");
}
else if(displayNumber == 2){
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(temp());
  lcd.print((char)223);
  lcd.print("F");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(humidity);
  lcd.print("%");
}

if(digitalRead(buttonPin) == HIGH){
  displayNumber = displayNumber + 1;
     if (displayNumber > 2){
      displayNumber = 1;
     }
  
}
delay(1000);
}

float temp(){

  float tempF = temperature * 9 / 5 +32;
  return tempF;
  
}

Do you have a 10k pulldown resistor connected between button pin and GND?