Thread: problem with continue

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    problem with continue

    I'm trying to write a program in which the user puts in a number, if its not a number you get prompted again to put in a number, if it is a number it just prints it back to you. simple, right?

    Code:
    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
    int n;
    printf("Enter a number:");
    scanf("%d" , &n);
    if(isalpha(n))
    	continue;
    else if(isdigit(n))
    	printf("you said %d and that's sweet\n");
    return 0;
    }
    anyway when I try to compile it(Borland if that matters) it says Misplaced continue in function main. how can I fix this? thanks guys

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Why not just do:

    Code:
    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
    int n;
    printf("Enter a number:");
    scanf("%d" , &n);
    if(isdigit(n))
    printf("you said %d and that's sweet\n");
    return 0;
    }
    Or, if that doesn't work:

    if (isdigit(n) && !isalpha(n))
    printf("you said %d and that's sweet\n");

    (dunno why you'd need that)

    Also, in your printf statement, you don't print the number. It should be:

    printf("you said %d and that's sweet\n", n);
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Both of you are wrong. You do not use any of the "is*" functions on integers. Yes, they take integers, but they expect the range to be a valid range for 'char'. They translate that decimal value into the ascii value of the corresponding character, and tell you if that is a character. They are meant to be used like so:
    Code:
    char  c = '1';
    
    if( isalpha( c ) )
        printf("%c is an alpha-numeric character.\n", c );
    You do not pass it a value like 200 and
    expect it to say that 200 is a number.

    Code:
    if( scanf("%d", &n ) == 1 )
        printf("%d is a number.\n", n );
    else
        printf("You entered an invalid value.\n");
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. Recursion Problem I think
    By clearrtc in forum C Programming
    Replies: 4
    Last Post: 07-31-2006, 07:10 PM
  3. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  4. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM