Thread: help with looping.

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    3

    help with looping.

    how do i loop this back using do/while. i must have it loop back to stating the question if the user types "y" and have it say have a nice day if the user types "n".

    #include <stdio.h>
    int main(void )
    {

    int i, is_prime=1;
    int num ;

    printf("Enter a positive integer greater than 1:", &num);
    scanf("%d", &num);
    for(i=2; i <= num/2; i++){
    if(num%i==0){

    is_prime=0;
    break;
    }
    }

    if(is_prime==1){
    printf("%d is a prime number.\n", num);
    }
    else{
    printf("%d is not a prime number.\n", num);
    }

    printf("do you wish to continue?[y/n]");

    return 0;

    }

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    127
    This should get you started.
    Code:
    int main(void)
    {
      char again;
    
      do {
        [...]
      } while (again == 'y');
      printf("Have a nice day!\n");
    
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd looping effect after exporting 3ds to .x annimation
    By Anddos in forum Game Programming
    Replies: 3
    Last Post: 01-06-2009, 01:43 PM
  2. problems with prototype function looping
    By dezz101 in forum C Programming
    Replies: 5
    Last Post: 04-29-2008, 06:03 AM
  3. looping went berserk
    By miryellis in forum C Programming
    Replies: 7
    Last Post: 09-21-2004, 01:59 PM
  4. Looping questions
    By Peyote in forum C++ Programming
    Replies: 3
    Last Post: 09-15-2003, 11:01 PM
  5. looping and input
    By Kinasz in forum C Programming
    Replies: 2
    Last Post: 03-17-2003, 07:12 AM