i am using an if/else if statement in my code as can be seen below.
hArea and vArea are functions that should be used if v or h is entered, however i am having problems with the invalid input section where i get a repetition in the output as seen below. if an invalid input is entered i want the function getType to run again and ask the user for another valid input.Code:void getType() { char type; printf("\nEnter wind turbine type (v or h):"); scanf("%c", &type); if (type == 'v' || type == 'V') { vArea(); } else if (type == 'h' || type == 'H') { hArea(); } else { printf("Invalid input!"); return getType(); }
Enter wind turbine type (v or h):k
Invalid input!
Enter wind turbine type (v or h):Invalid input!
Enter wind turbine type (v or h):
what in my code needs to be fixed so that the third line is removed and the output will then look like:
Enter wind turbine type (v or h):k
Invalid input!
Enter wind turbine type (v or h):
cheers