serial monitor, printing, reading

I've only been doing this 3 weeks so please have some patience. Some of these things must be easy but they are difficult for me to figure out.

  1. more a statement than a question. someone said get in the habit of using lots of variables so that what's i'm trying to do.

  2. phantom words, or parts of works show up in the serial monitor. why? how do i fix?

  3. why doesn't the serial input wait too long before moving on? is there a way to better control this?

  4. it seems like spacing is a problem too. it seems as if i have the same code but the outcome is different.

Coding take a lot of time and attention to detail. If someone forgets to a french fry on my plate, no big deal. If you forgot a semicolon, it can be stop you in you tracks.

BTW: I'm learning with code I found online in help forums, articles and apps. I modify it to learn. You may see your base code. If you do and and you don't want me to use it, I won't.

int dogs = 10;
int hotdogbuns = 100;
int mustard = 100;
int ketchup = 100;
int relish = 100;
int plates = 100;
int variables = 6;

int dogAte = 10;     // the number of dogs that ate hot dogs
int bunsAte = 10;    // the number of dogs that ate buns
int mustardAte = 4;  // only six dogs would eat the hog dogs with mustard
int ketchupAte = 9;    // one 1 dog did not likr ketchup
int relishAte = 2;      // only two dogs like relish

int (doggyGuess);

String dogAteQ ="How many of the 10 dogs that ate hot dogs?";
String bunsAteQ ="How many of the 10 dogs ate buns?";
String mustardAteQ ="How many of the 10 dogs are hot dohs with mustard?";
String ketchAteQ ="How many of the 10 dogs are hot dohs with ketchup?";
String relishAteQ ="How many of the 10 dogs are hot dohs with relish?";

void setup() {    // put your setup code here, to run once:

Serial.begin(9600);

delay (3000);

Serial.print("Ten dogs got togther to have hot dogs.");
Serial.println("");
Serial.println("Some dogs were pickier eaters than others.");

delay(1000);
        
Serial.print("\n\n");
Serial.print("How many dogs liked ketchup?");
while (Serial.available()==0){                //Wait for input
doggyGuess = Serial.parseInt(); }             //Read user input
Serial.print("  In our study ");
Serial.print(ketchupAte);
Serial.print(" out of ");
Serial.print(dogs);
Serial.print(" dogs liked ketchup.");
Serial.print("You picked: ");
Serial.print(doggyGuess);
delay(2000);

Serial.print("Ten dogs got togther to have hot dogs.");
Serial.println("");
Serial.println("Some dogs were pickier eaters than others.");
delay(1000);

Serial.print("\n\n\\n");
Serial.print("How many dogs liked mustard?");
while (Serial.available()==0){          //Wait for input
doggyGuess = Serial.parseInt(); }       //Read user input
Serial.print("  In our study ");
Serial.print(mustardAte);
Serial.print(" out of ");
Serial.print(dogs);
Serial.print(" dogs liked mustard.");
Serial.print("You picked: ");
Serial.print(doggyGuess);
delay(2000);

Serial.print("\n\n\\n");
Serial.print("How many dogs liked relish?");
while (Serial.available()==0){          //Wait for input
doggyGuess = Serial.parseInt(); }       //Read user input
Serial.print("  In our study ");
Serial.print(relishAte);
Serial.print(" out of ");
Serial.print(dogs);
Serial.print(" dogs liked relish.");
Serial.print("You picked: ");
Serial.print(doggyGuess);
delay(2000);


}

void loop() {
  // put your main code here, to run repeatedly:

}

Best,

Tony Perry

Your code (and it is repeated multiple times...)

  while (Serial.available() == 0) {             //Wait for input
    doggyGuess = Serial.parseInt();
  }             //Read user input

Basically says, "why there are no characters available on the Serial port, read an integer"

What you should be doing is "why there are no characters available on the Serial port, wait. Then read an integer"

  while (Serial.available() == 0) {
    //Wait for input
  }
  doggyGuess = Serial.parseInt();

Coding take a lot of time and attention to detail. If someone forgets to a french fry on my plate, no big deal. If you forgot a semicolon, it can be stop you in you tracks.

yes. Programming languages are funny that way - they don't guess at what you are trying to do

I just can't get the serial monitor to wait for an entry before moving on. Why?

On the plus side, my sm formatting is looking better.

int kids = 10;
int hotdogbuns = 100;
int mustard = 100;
int ketchup = 100;
int relish = 100;
int plates = 100;
int variables = 6;

int kidsAte = 10;     // the number of kids that ate hot dogs
int bunsAte = 10;    // the number of kids that ate buns
int mustardAte = 4;  // only six kids would eat the hog dogs with mustard
int ketchupAte = 9;    // one 1 kids did not likr ketchup
int relishAte = 2;      // only two kids like relish

int (guessdogAte);
int (guessbunsAte);
int (guessmustardAte);
int (guessketchupAte);
int (guessrelishAte);


String dogAteQ ="How many of the 10 kids ate hot dogs?";
String bunsAteQ ="How many of the 10 kids ate buns?";
String mustardAteQ ="How many of the 10 kids are hot dohs with mustard?";
String ketchAteQ ="How many of the 10 kids are hot dohs with ketchup?";
String relishAteQ ="How many of the 10 kids are hot dohs with relish?";

void setup() {    // put your setup code here, to run once:

Serial.begin(9600);

delay (3000);
Serial.print("Ten kids got togther to have hot dogs.");
Serial.println("");
Serial.println("Some dogs were pickier eaters than others.");


//
//
// KETCHUP
//
// 

delay(2000);
Serial.print("\n\n\n");
Serial.print("How many kids liked ketchup?");
while (Serial.available()==0){                //Wait for input
guessketchupAte = Serial.parseInt(); }             //Read user input
Serial.print("  In our study ");
Serial.print(ketchupAte);
Serial.print(" out of ");
Serial.print(kids);
Serial.print(" kids liked ketchup.");
Serial.print("You picked: ");
Serial.print(guessketchupAte);
delay(2000);


//
//
// MUSTARD
//
// 


delay (2000);
Serial.print("\n\n\n");
Serial.print("How many kids liked mustard?");
while (Serial.available()==0){                //Wait for input
guessketchupAte = Serial.parseInt(); }             //Read user input
Serial.print("  In our study ");
Serial.print(mustardAte);
Serial.print(" out of ");
Serial.print(kids);
Serial.print(" kids liked mustard.");
Serial.print("You picked: ");
Serial.print(guessmustardAte);



//
//
// RELISH
//
//

delay(2000);
Serial.print("\n\n\n");
Serial.print("How many kids liked relish?");
while (Serial.available()==0){                //Wait for input
guessrelishAte = Serial.parseInt(); }             //Read user input
Serial.print("  In our study ");
Serial.print(relishAte);
Serial.print(" out of ");
Serial.print(kids);
Serial.print(" kids liked relish.");
Serial.print("You picked: ");
//Serial.print(guessrelishAte);
delay(2000);


}

void loop() {
  // put your main code here, to run repeatedly:

}