I wrote my code for a program that finds the prime factors and distinct prime factors of any integer between 1 and 2000. However, now I need to write code that will loop the program and ask the user for another number until the user wants to stop. It would look as followed:
Do you want to try another number? Say Y(es) or N(o): y //Then it would ask for a number between 1 and 2000, and the program will run.
Do you want to try another number? Say Y(es) or N(o): n ---> "Thank you for using my program. Good Bye!:
I have attempted writing the code for this, but as you can see I got stuck at the end where I put the comments in place of code. I don't know how to loop it so the program will repeat again. That is the only thing I feel like I am stuck on. I feel like my code below for this problem is correct, it just needs to loop the program which I am unsure on how to do. Hope you can help.
int main() {
unsigned num;
char response;
printf("Please enter a positive integer greater than 1 and less than 2000:");
scanf("%d", &num);
if (num > 1 && num < 2000){
printf("The distinctive prime facters are given below: \n");
printDistinctPrimeFactors(num);
printf("All of the prime factors are given below: \n");
printPrimeFactors(num);
}
else {
printf("Sorry that number does not fall within the given range.\n");
}
printf("Do you want to try another number? Say Y(es) or N(o): \n");
response = getchar();
if(response == 'Y' || answer == 'y')
//then loop back through program
//else print "Good Bye!"
}
return 0;
}