hello,
i've tried looking at the FAQs etc. on this topic, but my knowledge of C is very, very small. My problem is that i'm trying to make a program that requests the user to put in a positive integer, but anything other than a positive integer asks the user to try again.
This is what i've done so far:
So far it won't take negative numbers, but if i put in a character it loops the for statement (sorry if thats the wrong terminology)Code:#include <stdio.h> void main() { int i, j; printf("Please enter a positive integer:"); scanf("%d", &i); while (i<=0){printf("\nYou have not entered a positive integer.\n\n"); printf("Please enter a positive integer:"); scanf("%d", &i);} j=i; for (i=0; i<j; i++){printf("It Worked!\n");} }
How do i get it to request the user to re-enter a positive integer if they had input a character the first time?
thanks for any help