Even if the input is "boy" it will still return "Kai"

Kindly help me with this supposed simple line of codes sir. It kept returning wrong answer.

Even if the input is "boy" it will still return "Kai"

Kindly help

Processing: ard.txt...

Maybe you haven't understood line-endings.
You've certainly misunderstood forum posting guidelines.

Kindly help out. I am having serious headache. Thanks

Take some Neurofen

2 Likes

As a debugging aid, print out the value of the variable "Choice" to see what is in it.

My sincere apologies if I have disobeyed the rules. I am new and I was asked to pick from a categories , I did and I realise I couldn't lunch a new topic. The only option left was to use existing one.

I did but it was "Kai" that came out even if the input is "boy".

I actually have a wider area of application but had to summarize it . But I am still having the same problem.

I used Arduino mega, I have equally tried with nano board and another computer but same problem.

It is supposed to return "Hi" if the choice is "boy" and return "Kai" if the choice is something else. But all returns are "Kai" irrespective of the "choice".

@taiwoaa

TOPIC SPLIT
PLEASE DO NOT HIJACK

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Hello
Post the current sketch well formated, with comments and in code tags "</>" to see how we can help.

And see reply #2

String choice;

Void setup () {

Serial.begin (9600);

}

Void loop () {

while (Serial.available()==0){ }

choice=Serial.readString();

If (choice == "boy" ) {

Serial.println( "You are welcome");

}

else {
Serial.println ("Try next time");
}

}

//Above are the lines of code, but it kept returning "try next time" irrespective of the value of choice. Even when choice is "boy"

Please remember to post your actual code, in code tags.

Have you checked your line ending yet?

dont forget to add

typedef void Void;

Does the compiler likes your sketch?

Yes. There was no issue. It "run" very well. But when I enter "boy" on the serial monitor, it displays "pls enter correct value"

I'll try one more time.
Have you checked the line ending control on the serial monitor?

Yes there was.
The code you posted could not have compiled, therefore it could not have run.

Not to mention "pls enter correct value" is nowhere near the code posted

String choice;

void setup () {

Serial.begin (9600);

}

void loop () {

while (Serial.available()==0){ }

choice=Serial.readString();

If (choice == "boy" ) {

Serial.println( "You are welcome");

}

else {
Serial.println ("Try next time");
}

}

If I tell you that I don't think there is anything wrong with your code (apart from the missing code tags), WILL YOU PLEASE TELL ME WHAT THE LINE-ENDING CONTROL ON THE SERIAL MONITOR IS SET TO?