Die Schleife überspringt eine scanf-Anweisung nach dem ersten Mal
Hier ist der Code für main ():
int main (void)
{
float acres[20];
float bushels[20];
float cost = 0;
float pricePerBushel = 0;
float totalAcres = 0;
char choice;
int counter = 0;
for(counter = 0; counter < 20; counter++)
{
printf("would you like to enter another farm? ");
scanf("%c", &choice);
if (choice == 'n')
{
printf("in break ");
break;
}
printf("enter the number of acres: ");
scanf("%f", &acres[counter]);
printf("enter the number of bushels: ");
scanf("%f", &bushels[counter]);
}
return 0;
}
Jedes Mal, wenn das Programm den ersten Scanf durchläuft, funktioniert es einwandfrei, aber beim zweiten Durchlauf der Schleife wird der Scanf zur Eingabe eines Zeichens nicht ausgeführt.