Hi
I'm a newbie to programming and I'm encountering issues with the following program.
The compiler tells me that the variable after the while is not recognized.
What I especially don't understand is that the variable is defined and accepted in the character input and the swicth but later on is not recognized. I'm sure of this because I wrote the entire program, and then compiled it afterwards. I was therefore able to see the compiler advancing as the code was corrected
The error message is "cannot find symbol - variable choix"
Sorry for the french, I'm in a french programming class
do { System.out.println ("1); Acheter Patons "); System.out.println (" 2); Fabriquer baguettes "); System.out.println (" 3); Vendre baguette "); System.out.println (" q ou Q); Quitter "); char choix = Clavier.lireChar(); switch (choix) { //demande le nombre de patons a achete case 1: System.out.println (" Nombre de patons :"); nombreDePatons = Clavier.lireDouble(); while (nombreDePatons <= 0 ){ System.out.println (" Erreur : choix non valide! "); } patons = patons + nombreDePatons; accumulateurPatons = accumulateurPatons + nombreDePatons; break; // demande le nombre de baguette à produire case 2: System.out.println (" Nombre de baguette : "); nombreDeBaguettes = Clavier.lireDouble(); while (nombreDeBaguettes <= 0 ){ System.out.println (" Erreur : choix non valide! "); } if (nombreDeBaguettes > nombreDePatons) { System.out.println ("Pas de patons, pas de baguette! "); } else if (nombreDeBaguettes <= nombreDePatons) { baguette = baguette + nombreDeBaguettes; patons = patons - nombreDeBaguettes; } break; // demande le nombre de baguette à vendre case 3: System.out.println (" Nombre de baguette : "); baguetteAVendre = Clavier.lireDouble (); while (baguetteAVendre <= 0 ){ System.out.println (" Erreur : choix non valide! "); } if (baguetteAVendre > nombreDeBaguettes) { System.out.print ("Pas de baguette, pas de ventes! "); } else if (baguetteAVendre <= nombreDeBaguettes) { baguette = baguette - baguetteAVendre; accumulateurBaguette = accumulateurBaguette + baguetteAVendre; } default: System.out.println (" Erreur : choix non valide! "); } } while (choix != 'q' && choix != 'Q') ;
Thanks in advance
Christian