Hello,
I am creating code that seemed fine, except when I entered a single character, or strings instead of numbers, the console continually prompts for user input and it is difficult to terminate the console. Below is the code
printf("\nHow many computers do you want to update?\n");
scanf("%d", &numComputersToUpdate);
do{
determineInstallationTargets();
}while (counter < numComputersToUpdate) ;
determineInstallationTargets(); looks fine - except when I enter a character or string
int determineInstallationTargets{
int menuchoice;
menuchoice = 0;
printf("Enter 1 or 2 from menu\n");
scanf("%d", &menuchoice);
switch (menuchoice)
{//start switch menuchoice
case 1:
print ("Case 1\n");
counter++;
break;
case 2:
print ("Case 2\n");
threadCounter++;
break;
default:
printf("Please only enter 1 or 2.\n");
break;
}//end switch menuchoice
return 0;
}
I tried using a try-throw-catch block, but it still doesn't catch the error if someone enters a character or string for menuchoice.
Please advise the best way to implement try-throw-catch, or any other method to handle bad input.