Thread: isdigit function

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    isdigit function

    Hi I hope someone can help me with this. I am working on a program that asks the user to select an item from the menu 1-6. I have a while statement that returns to the loop if the user selects any other number. while(userAns<1)||(userAns>6)) I am trying to create an isdigit if statement that will return to the loop if the user selects a char. I have: if(isdigit(c)) I declared my char c, and have the #include<ctype.h> Should the while statement and the if statement be together? The while statement works but the if just loops. Thanks [EMAIL=joejonsmom]function isdigit What am I missing?

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    You could help us help you by posting your attempt so we can have a look at it and see if you are doing things right or wrong.

    ~/

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    isdigit

    Hi actually I got this to work finally but now my if statement to make the loop work is not.

    }
    printf("Would you like to select another option?\n\n");
    printf("1=Yes and 2=No\n\n",ans);
    scanf("%d",&ans);

    if(ans==1)
    clrsc();
    else if(ans!=1)
    return 0;
    }

    I know this is something really easy but I appreciate any help I can get. Thanks

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
     printf("1=Yes and 2=No\n\n",ans);  // Why?
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    3

    if loop

    I need a loop which gives the user an option to exit or return to the menu to select another currency.
    What would be a better option Thanks

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Perhaps this old post may be of interest.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM