Hey guys I ned some quick help here with a little program, please.

This is a discussion on Hey guys I ned some quick help here with a little program, please. within the C++ Programming forums, part of the General Programming Boards category; Well you're mixing up the {} - adding them where they're not needed, and removing them where they are. Code: ...

  1. #31
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Well you're mixing up the {} - adding them where they're not needed, and removing them where they are.

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    int EWord(char *str);
    void LWord(char *str);
    
    int isVowel( char ch ) {
        int res = 0;
        ch = tolower( ch );
        if(ch == 'a' ||
            ch == 'e' ||
            ch == 'i' ||
            ch == 'o' ||
            ch == 'u') res = 1;
        return res;
    }
    int beginsConsonant( char word[] ) {
        return !isVowel( word[0] );
    }
    
    int main(void) {
        char Word[100];
        printf( "Welcome to the Pig Latin Translator!\n\n" );   
        printf( "Please enter your word(s):\n\n" ); 
        while(scanf( "%s", Word ) == 1) {
            if(stricmp( Word, "stop" ) == 0) return 0;
            if(EWord( Word )) LWord( Word );
        }
        return 0;
    }
    
    int allConsonant( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for(i = 0 ; i < len ; i++) {
            if(isVowel( word[i] )) res = 0;
        } //!! ADDED
        return res;
    }
    
    void pigLatin( char word[] ) {
        if(beginsConsonant( word ) && !allConsonant( word )) {
            printf( "%s%cay ", &word[1], word[0] );
        } else {
            printf( "%sway ", word );
        }
        //!! REMOVED }
    }
    Does your editor preserve this indentation?

    There are many free code editors around which understand program indentation, and know how to match up {} so you can see whether they are balanced or not

    Which OS / Compiler are you using

  2. #32
    Unregistered
    Guest
    Error: Expression Syntax in function allConstant

    for what i can see

    Code:
    int allConsonant ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
            <--------- (missing for loop brace)
        return res;
        }
    e.g

    Code:
    int allConsonant ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        } <-------- brace in place
        return res;
        }

  3. #33
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Ok Guys I did what you two said and it got rid of the errors that I got before, But now I have 2 different errors. My current code is below and the errors will be after it. Im stilll messing with stuff to see whats wrong, but I want to keep you guys updated.

    Salem, what are you asking me with the first question (Does your editor preserve this indentation?) ?? And the compiler I am using is called Turbo C.

    Heres my current code:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    int EWord(char *str);
    void LWord(char *str);
    int isVowel ( char ch ) {
        int res = 0;
        ch = tolower( ch );
        if ( ch == 'a' ||
             ch == 'e' ||
             ch == 'i' ||
             ch == 'o' ||
             ch == 'u' ) res = 1;
        return res;
    }
    
    int beginsConsonant ( char word[] ) {
        return !isVowel( word[0] );
    }
    
    
    int main(void)
    {
       char Word[100];
    
       printf("Welcome to the Pig Latin Translator!\n\n");    
       printf("Please enter your word(s):\n\n");
    
    while(scanf("%s", Word) == 1) 
    {
    if( stricmp( Word, "stop" ) == 0 ) return 0; 
    
     
    if(EWord(Word)) LWord(Word); 
    }
    return 0; 
    }
    
    int allConsonant ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        }
        return res;
        }
    void pigLatin ( char word[] ) {
        if ( beginsConsonant(word) && !allConsonant(word) ) {
            printf( "%s%cay ", &word[1], word[0] );
        } else {
            printf( "%sway ", word );
        }
    }
    The two errors are:
    Linker Error: Undefined symbol '_LWord' in module PIGLAT10.TXT
    Linker Error: Undefined symbol '_EWord' in module PIGLAT10.TXT

    *Also there is NOTHING highlighted in the program to show the errors. So I dont know whats wrong.

  4. #34
    Registered User
    Join Date
    Oct 2001
    Posts
    38
    Looks like I spoke too soon.

    Ok I changed some things and my new current code is below. Now the changes I made made the code able to run. So it runs perfectly. BUT and this is a big but. Though it runs, it does NOT translate any words at all. NONE, it runs but just stays there waiting for words, I type them in, it doesnt translate and it just puts a cursor for the next word to be typed in. The ONLY word it recognizes is "Stop" and it will end the running program just like I want it too. But it just doesnt translate. Now Im really stuck. Im guessing everything is correct, I just have to put things in different orders. Lets see what you guys can figure out. Thanks for your help

    My code:

    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    int EWord(char *str);
    void LWord(char *str);
    int isVowel ( char ch ) {
        int res = 0;
        ch = tolower( ch );
        if ( ch == 'a' ||
             ch == 'e' ||
             ch == 'i' ||
             ch == 'o' ||
             ch == 'u' ) res = 1;
        return res;
    }
    
    int beginsConsonant ( char word[] ) {
        return !isVowel( word[0] );
    }
    
    
    int main(void)
    {
       char Word[100];
    
       printf("Welcome to the Pig Latin Translator!\n\n");    
       printf("Please enter your word(s):\n\n");
    
    while(scanf("%s", Word) == 1) 
    {
    if( stricmp( Word, "stop" ) == 0 ) return 0; 
    
     
    if(EWord(Word)) LWord(Word); 
    }
    return 0; 
    }
    
    int EWord ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        }
        return res;
        }
    void LWord ( char word[] ) {
        if ( beginsConsonant(word) && !EWord(word) ) {
            printf( "%s%cay ", &word[1], word[0] );
        } else {
            printf( "%sway ", word );
        }
    }

  5. #35
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Your current EWord
    Code:
    int EWord ( char word[] ) {
        int len = strlen( word );
        int i, res = 1;
        for ( i = 0 ; i < len ; i++ ) {
            if ( isVowel(word[i]) ) res = 0;
        }
        return res;
        }
    Your original EWord
    Code:
    int EWord(char *str) 
    { 
    int Cnt = 1; 
    
    while(*str) 
    if(!isalpha(*str++)) Cnt = 0; 
    
    return !!Cnt; 
    }
    If you type in a word with no vowels at present, it does work, its just that your EWord function calls isVowel rather than isascii.

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hey Guys! I Need Some Help Here!
    By Ruski in forum C++ Programming
    Replies: 6
    Last Post: 06-27-2002, 02:13 AM
  2. Hey i got a quick Question
    By cis in forum C Programming
    Replies: 1
    Last Post: 03-15-2002, 09:12 PM
  3. Hey guys, wanna see a picture of me?
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 53
    Last Post: 11-29-2001, 03:56 PM
  4. Hey Guys
    By D4050 in forum C Programming
    Replies: 0
    Last Post: 10-01-2001, 06:20 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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