help WHILE STATEMENT

This is a discussion on help WHILE STATEMENT within the C Programming forums, part of the General Programming Boards category; THE PROBLEM ASK FOR A WHILE STATEMENT IN REPLACE OF THE DO-WHILE....I CAN'T SEEM TO GET IT. PLEASE HELP...THANKS TO ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    17

    help WHILE STATEMENT

    THE PROBLEM ASK FOR A WHILE STATEMENT IN REPLACE OF THE DO-WHILE....I CAN'T SEEM TO GET IT.
    PLEASE HELP...THANKS TO ALL THE PROGRAMMERS THAT HELP ME SO FAR!!!!



    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
    char inChar;
    do
    {
    printf("\npush any key(type and f to stop)");
    inChar=getchar();
    inChar=tolower(inChar);
    getchar();
    if ( isalpha (inChar))
    printf("\nthe character entered is a letter.");
    else if (isdigit(inChar))
    printf("\nthe character entered is a digit.");
    } while (inChar !='f');
    }

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Please don't use all caps, it's harder to read.
    Code:
    #include<stdio.h>
    #include<ctype.h>
    
    int main()
    {
        int inChar;
    
        printf("\npush any key(type and f to stop)");
    
        while ((inChar = getchar()) != 'f')
        {
            inChar=tolower(inChar);
            getchar();
    
            if ( isalpha (inChar))
                printf("\nthe character entered is a letter.");
            else if (isdigit(inChar))
                printf("\nthe character entered is a digit.");
    
            printf("\npush any key(type and f to stop)");
        }
    }
    p.s. What the alphabet would look like without q and r.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    17
    thax alot..but when i tried to run it.
    it said "can't execute"

  4. #4
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    >it said "can't execute"
    That doesn't help. It works fine for me, and should for you too if the code you posted worked.
    p.s. What the alphabet would look like without q and r.

  5. #5
    thebox
    Guest

    Wink While loops

    m8 - Just noticed on the firstbit of code here that you got a semicolon ( after your while statement - that'll make it terminate

  6. #6
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    > after your while statement - that'll make it terminate
    That's the correct syntax for a do..while statement.
    p.s. What the alphabet would look like without q and r.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 06:19 AM
  2. Meaning of this statement?
    By @nthony in forum C Programming
    Replies: 7
    Last Post: 07-16-2006, 03:57 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 10:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21