I'm using a Yes/No user prompt to determine whether the user wants to go through the program or exit the program...when you type y or Y it will go through the program again. However, any other character, not just n or N, will discontinue the program. I was wondering how I could fix this?
int main() {
unsigned num;
char response;
do {
printf("Please enter a positive integer greater than 1 and less than 2000: ");
scanf("%d", & num);
if(num > 1 && num < 2000) {
printf("All the prime factors of %d are given below: \n", num);
printPrimeFactors(num);
printf("\n\nThe distinct prime factors of %d are given below: \n", num);
printDistinctPrimeFactors(num);
} else {
printf("Sorry that number does not fall within the given range.\n");
}
printf("\n\nDo you want to try another number? Say Y(es) or N(o): ");
getchar();
response = getchar();
}
while (response == 'Y' || response == 'y'); // if response is Y or y then program runs again
printf("Thank you for using my program. Good Bye!\n\n"); //if not Y or y, program terminates
return 0;
}