Home Distance Program

Hello friends, I am trying to get a better understanding of using the if statements and decided that a good way to learn would be to write a program that asked the user a question of which room he was starting in and then would ask where his destination room would be. By having different starting rooms to choose and different rooms to end, I figured that the if statement would be used many times. For the time being I'm getting an error that says [u]'ser' was not declared in this scope[/u] . I only posted 2 rooms to start in just to get the program started. I figured the rest would be similar repetition of the above. If anyone can direct me, please help. Eventually I would like to have the Arduino compute the distances, but for now i'll take care of it this way. Thanks for reading

Here's what I have so far.......

// Room Distance Program void setup() { Serial.begin(9600); Serial.print("Room Distance Program"); delay(3000); Serial.print("Your starting point options are the following: Gerardo Room, Living Room, Kitchen, Bathroom, Mom Room.....Choose one...."); }

void loop() { if(Serial.available()) char ser = Serial.read(); { if(ser == "Gerardo Room") { Serial.print("Gerardo Room"); delay(2000); { Serial.print("What is your ending point"); delay(500);} if(ser == 'Living Room') {Serial.print("15 feet");} if(ser == 'Kitchen') {Serial.print("18");} if(ser == 'Bathroom') {Serial.print("23");} if(ser == 'Moms Room') {Serial.print("25");} }

if(ser == 'Living Room') Serial.print("Living Room"); delay(2000); {Serial.print('Which room is your ending point'); if(ser == 'Gerardo Room') {Serial.print("15");} if(ser == 'Living Room') {Serial.print("0");} if(ser == 'Kitchen') {Serial.print("27");} if(ser == 'Bathroom') {Serial.print("32");} if(ser == 'Moms Room') {Serial.print("34");} }}}

'ser' was not declared in this scope

You forgot to declared the variable "ser".

In the IDE program, Look under "Reference" and look into "Examples"

int example; // Declare my variable

setup()

{

}

loop()

{
   example=25;
}

Oh one thing. Please select # icon when you want to show your code.

Nice effort by the way.

void loop()
{  
  if(Serial.available())
    char ser = Serial.read();
  {  
    if(ser == "Gerardo Room")

should read

void loop()
{  
  if(Serial.available())
  {
    char ser = Serial.read();
    
    if(ser == "Gerardo Room")

If you use Ctrl-T in the IDE, it will auto format your code, making this kind of error easier to spot.

Also:if(ser == "Gerardo Room")
A single “char” is never going to be the same as a string.

And a single “char” is never going to be the same as multi-char constant:

if(ser == 'Living Room')

( " != ’ )

Please use the # icon on the editor’s toolbar when posting code.

(Hint: go easy on the strings - if your code grows much more, you’re going to use too much RAM)