Pushbutton seemingly random problems

Hello, Arduino forum!

I have purchased my Arduino UNO and am having lots of fun making random things, but I keep having problems with my pushbuttons.

In this specific project I was looking to make 7 segment display show numbers 0-9 and increase every time I press a button. Everything works fine with the display, and numbers are correct as well but the problem seems to be with the pushbutton that when read keeps showing as 1 (or HiGH, honestly still not sure should go research).

As a side note, when I unplug the button cord from the pin all together it just keeps switching from 0 and 1 randomly.

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int pinDOT = 9;
int pinbutton = 11;
int displayDigit = 0;

void setup() {
    pinMode(pinA, OUTPUT);
    pinMode(pinB, OUTPUT);
    pinMode(pinC, OUTPUT);
    pinMode(pinD, OUTPUT);
    pinMode(pinE, OUTPUT);
    pinMode(pinF, OUTPUT);
    pinMode(pinG, OUTPUT);
    pinMode(pinDOT, OUTPUT);
    pinMode(pinbutton, INPUT);
    Serial.begin(9600);
    
}

void loop() {
    int button_state = digitalRead(pinbutton);
    showDisplay(displayDigit);
    if(digitalRead(pinbutton) == 1)
    {
      displayDigit++;
      if(displayDigit > 9)
      {
        displayDigit = 0;
      }
    }
    Serial.print("|");
    Serial.print(digitalRead(pinbutton));
    Serial.print("|");
    Serial.println(displayDigit);
    delay(500);
    
}

void showDisplay(int x)
{
  switch(x){
  case 0: 
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinE, HIGH);
    digitalWrite(pinF, HIGH);
    break;
    
  case 1: 
    turnOffDisplay();
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    break;
  case 2:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinG, HIGH);
    digitalWrite(pinE, HIGH);
    digitalWrite(pinD, HIGH);
    break;
  case 3:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinG, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    break;
  case 4:
    turnOffDisplay();
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinG, HIGH);
    digitalWrite(pinF, HIGH);
    break;
  case 5:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinF, HIGH);
    digitalWrite(pinG, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    break;
  case 6:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinF, HIGH);
    digitalWrite(pinE, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinG, HIGH);
    break;
  case 7:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    break;
  case 8:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinE, HIGH);
    digitalWrite(pinF, HIGH);
    digitalWrite(pinG, HIGH);
    break;
  case 9:
    turnOffDisplay();
    digitalWrite(pinA, HIGH);
    digitalWrite(pinB, HIGH);
    digitalWrite(pinC, HIGH);
    digitalWrite(pinD, HIGH);
    digitalWrite(pinG, HIGH);
    digitalWrite(pinF, HIGH);
    break;
  }
}
void turnOffDisplay()
{
  digitalWrite(pinA, LOW);
    digitalWrite(pinB, LOW);
    digitalWrite(pinC, LOW);
    digitalWrite(pinD, LOW);
    digitalWrite(pinE, LOW);
    digitalWrite(pinF, LOW);
    digitalWrite(pinG, LOW);
}

I will attach a picture with this post, please excuse bad quality, I will do my best to figure out how to make schematics in the future.

Edit: Nevermind, the image won't upload, but I didn't do anything special with it, just 5v and ground on one side and another wire going from the opposite side to pin 11

You have wired a pull down resistor (say 10k) on the button?

Yes, I have, both on the ground wire and output wire, I have tried removing the resistor on the out wire but it didn't seem to make a difference.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html.

You image needs to be less than about 1Mb in size, if it is too big you can load it into a graphics app and resize it. about 800pixels on the longest size is good.

Tom... :)

WojtekTB: Yes, I have, both on the ground wire and output wire, I have tried removing the resistor on the out wire but it didn't seem to make a difference.

Please post a diagram, hand drawn will do, of your circuit. I do not understand what you have written.

Personally I would use INPUT_PULLUP in the pinMode() and wire the input to be pulled LOW (to GND) when activated. No external resistors needed.