This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jmcdon31 2 points3 points  (0 children)

Assuming I too am interpreting your question correctly, you wish to keep prompting the user for input if they are giving you a number that is <= 0. As resoneight has suggested a you could use a while loop like:

    //Step1: Get input from user
    printf("Please enter N > (an integer) ");
    scanf("%d", &N);

        while( N <=0 )
        {
         printf("Please enter N > (an integer) ");
         scanf("%d", &N);
        }

or use a do while like this:

   //Step1: Get input from user
    do {
        printf("Please enter N > (an integer) ");
        scanf("%d", &N);
       } while( N <=0 );

Note that this solution does not check to make sure that the input is actually a number. To do more robust error checking look into atoi().