Input from serial monitor each time zero entered automatically

I want input from serial monitor and each time after entering number I received 0 entered automatically. can any one help me to sort out this problem. values getting on serial monitor is presented in last of code.
my detailed code is presented here

String msg="Please enter your number";
String msg1="You entered number: ";
int mynumber;
int red=8;
int green=9;
int blue=10;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(red,OUTPUT);
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(msg);
  while(Serial.available()==0){
    
  }
mynumber=Serial.parseInt();
if(mynumber==1){
  digitalWrite(red,HIGH);
}
else{
  digitalWrite(red,LOW);
}

if(mynumber==2){
  digitalWrite(green,HIGH);
}
else{
  digitalWrite(green,LOW);
  }
  if(mynumber==3){
    digitalWrite(blue,HIGH);
  }
  else{
    digitalWrite(blue,LOW);
  }
Serial.print(mynumber);
}

Serial monitor response is given here
Please enter your number
1Please enter your number
0Please enter your number

Hello

Serial.parseInt();

returns an int long.

https://www.arduino.cc/reference/en/language/functions/communication/serial/parseint/

1 Like

Make sure that the Serial Monitor is set for "no line ending" in the pull down menu at the lower right.

1 Like

Thank you dear now it works fine
thanks alot