0

I haven't figured out yet how to avoid a user entrance like a letter or symbol into the scanf line, because if that happens, the code will get into permanet loop. So, how can I strictly get as a answer from the user a number? I just entered a letter, like A or B it begins a non ending loop. Hope someone can help. Thanks in advance.

#include <stdio.h>
int main()
{
float area;
int seed_numbers, x, y;
char option, optionII;
printf("Choose the size of the area\n");
printf("for reforestation: from 1 to 10 ha: ");
scanf("%f",&area);
while(area<1 || area>10){
    printf("Not allowed option. Wright a number between 1 to 10 ha: ");
    scanf("%f",&area);
}
return 0;
}
Daniel Montenegro
  • 1,491
  • 2
  • 15
  • 15

0 Answers0