Incorrect output printing to serial monitor

Hello,

I'm new to using Arduino and am having some issues with printing the right output to the serial monitor.

My code is as follows:

void setup(){
// Setting up the Serial Monitor
Serial.begin(9600);
Serial.println("What spice do you want?");
}

void loop() {

// Initiates when we receive input from the user
if (Serial.available() > 0){

// Accepting Spice Name
String choice = Serial.readString();
choice.trim();
Serial.println(choice);

// Accepting Spice Quantity
Serial.println("How much would you like?");
int spoons = Serial.parseInt();
Serial.println(spoons);
}
}

So this should accept user input and then print those values out again. For example, if I input choice = "abcd" and spoons = "0.5" it should print as:
"What spice do you want?"
"abcd"
"How much would you like?"
"0.5"

However, the following is the output that is observed:
"What spice do you want?"
"abcd"
"How much would you like?"
"0"
"0.5"

I'm not very sure where the "0" is coming from and I was wondering if y'all had any ideas/suggestions to address it?

Thank you for your time!

Set the serial monitor line ending control to "none" or "no line ending"

Welcome to the forum

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to read, copy and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.