Thread: Problem with my program i cant figure out...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    17

    Problem with my program i cant figure out...

    Ive been trying to get this program to work for the past two days and i cant seem to find whats wrong with it. bear, with me if its very obvious for you guys but a little hint would be much appreciated.

    the purpose of this program is to check if user inputted character is a vowel or consonant in the Hawaiian language. the program is split into three different files, a header file, a .c file for two functions, and a driver.c file to test the functions. oh, and also a makefile to execute the program.

    here is the header file
    Code:
    /* header file for letters.c */
    
    int is_vowel(char ch);
    
    int is_consonant(char ch);
    
    #define TRUE 1
    #define FALSE 0
    and the .c file for the int is_vowel and int is_consonant functions.
    Code:
    /* functions that test if a character is a vowel or consonant in the hawaiian language. */
    
    #include "letters.h"
    
    int is_vowel(char ch)
    {
            switch(ch)
             {
                    case 'a': return TRUE;
                            break;
                    case 'A': return TRUE;
                            break;
                    case 'e': return TRUE;
                            break;
                    case 'E': return TRUE;
                            break;
                    case 'i': return TRUE;
                            break;
                    case 'I': return TRUE;
                            break;
                    case 'o': return TRUE;
                            break;
                    case 'O': return TRUE;
                            break;
                    case 'u': return TRUE;
                            break;
                    default: return FALSE;
            }
    }
    
    int is_consonant(char ch)               
    {
            switch(ch)
             {
                    case 'h': return TRUE;
                            break; 
                    case 'H': return TRUE;
                            break; 
                    case 'k': return TRUE;
                            break;
                    case 'K': return TRUE;
                            break;
                    case 'l': return TRUE;
                            break; 
                    case 'L': return TRUE;
                            break; 
                    case 'm': return TRUE;
                            break; 
                    case 'M': return TRUE;
                            break; 
                    case 'n': return TRUE;
                            break; 
                    case 'N': return TRUE;
                            break; 
                    case 'p': return TRUE;
                            break; 
                    case 'P': return TRUE;
                            break; 
                    case 'w': return TRUE;
                            break; 
                    case 'W': return TRUE;
                            break; 
                    case '`': return TRUE;
                            break; 
                    default: return FALSE;
            }
    }
    and the driver.c to test the two functions
    Code:
    /* driver to test letters.c */
    
    #include "letters.h"
    #include <stdio.h> 
    #define FLUSH while(getchar() != '\n');
    
    main()
    {
       char ch;
    
            printf("Please enter a Hawaiian letter to be tested for being either a vowel or consonant:");
            
            while( (ch = getchar()) != EOF )
             {   
                    if( is_vowel(ch) == TRUE )
                      printf("The character is a vowel\n");
                    else
                      printf("The character is not a vowel or consonant\n");
    
                    if( is_consonant(ch) == TRUE )
                      printf("The character is a consonant");
                    else
                      printf("The character is not a vowel or consonant\n");
            
                    printf("Please enter the next character to be tested\n");
            FLUSH
            } 
    }
    the problem i am having is whenever i compile and run the program and type in say the vowel "a", the program prints both "the character is a vowel" and "The character is not a vowel or consonant" statement. it does the same if the letter is a consonant.

    ....idk whats wrong????

    Edit: just noticed, sorry for using an implicit main.
    Last edited by youareafever; 10-31-2008 at 01:06 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  2. Replies: 2
    Last Post: 04-25-2005, 11:59 AM
  3. Some Problem With My Program
    By Americano in forum C Programming
    Replies: 5
    Last Post: 10-18-2003, 01:58 AM
  4. problem with 2d array program.
    By Niloc1 in forum C Programming
    Replies: 1
    Last Post: 04-08-2002, 05:47 PM
  5. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM