Serial Monitor is incorrectly reading my inputs???

I have an example program which runs perfect but when interacting with it thru the serial monitor I am having issues. The program asks the user for input, then displays it, and tell you if your answer is right or wrong. Very simple, but when I send a value thru the serial monitor, like 15, it says that I inputted 34 when I actually inputted 15. It very random, and it never yields the number i input. How do I fix this? I thought it was my computer but I tried on a different one and had the same issue. Also used an arduino nano, no difference. I am not sure it is the code or not either? Like i said its an example code from a books file library.

// Project 17 - Making a Binary Quiz Game
#define DATA 6 // connect to pin 14 on the 74HC595
#define LATCH 8 // connect to pin 12 on the 74HC595
#define CLOCK 10 // connect to pin 11 on the 74HC595
int number = 0;
int answer = 0;
void setup()
{
  pinMode(LATCH, OUTPUT); // set up the 74HC595 pins
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA, OUTPUT);
  Serial.begin(9600);
  randomSeed(analogRead(0)); // initialize the random number generator
  displayNumber(0); // clear the LEDs
}
void displayNumber(byte a)
{
  // sends byte to be displayed on the LEDs
  digitalWrite(LATCH, LOW);
  shiftOut(DATA, CLOCK, MSBFIRST, a);
  digitalWrite(LATCH, HIGH);
}
void getAnswer()
{
  // receive the answer from the player
  int z = 0;
  Serial.flush();
  while (Serial.available() == 0)
  {
    // do nothing until something comes into the serial buffer
  }
  // one character of serial data is available, begin calculating
  while (Serial.available() > 0)
  {
    // move any previous digit to the next column on the left; in
    // other words, 1 becomes 10 while there is data in the buffer
    answer = answer * 10;
    // read the next number in the buffer and subtract the character '0'
    // from it to convert it to the actual integer number
    z = Serial.read() - '0';
    // add this digit into the accumulating value
    answer = answer + z;
    // allow a short delay for any more numbers to come into Serial.available
    delay(5);
  }
  Serial.print("You entered: ");
  Serial.println(answer);
}
void checkAnswer()
{
  //check the answer from the player and show the results
  if (answer == number) // Correct!
  {
    Serial.print("Correct! ");
    Serial.print(answer, BIN);
    Serial.print(" equals ");
    Serial.println(number);
    Serial.println();
  }
  else // Incorrect
  {
    Serial.print("Incorrect, ");
    Serial.print(number, BIN);
    Serial.print(" equals ");
    Serial.println(number);
    Serial.println();
  }
  answer = 0;
  delay(10000); // give the player time to review his or her answers
}
void loop()
{
  number = random(256);
  displayNumber(number);
  Serial.println("What is the binary number in base-10? ");
  getAnswer();
  checkAnswer();
}

Read all the bytes then do your math.

.

its hard to explain the situation.

The numbers i type on my keyboard are not the ones being received by the serial monitor, random numbers are making there way to the serial monitor. Something is happening in between the transfer of information and I cant figure it out.

Here is another example of it

int number;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  number=0;
  Serial.flush();
  while(Serial.available() == 0){
    }
    
    while(Serial.available()>0)
    {
      number=Serial.read()-'0';
      }
      //print the info
      Serial.print("You entered ");
      Serial.println(number);
      Serial.print(number);
      Serial.print(" multiplied by 2 is ");
      number= number*2;
      Serial.println(number);

}

for this code I submit 10 into the serial monitor and it yields this

You entered 1
1 multiplied by 2 is 2
You entered -38
-38 multiplied by 2 is -76

This is what is confusing me, why is it bugging out?

At the top of the serial monitor screen is a single line for your input. If you input 15 and you see 15 there, then clearly, your serial monitor is not incorrectly reading your input. So what IS on the top line?

Yes your correct, didnt describe it correctly. What I am typing does appear on the top bar of the serial monitor, but its after I hit send that I start having issues.

You are only reading one byte and then flushing the rest of your serial buffer.