Please help me with this simple program?

#include <iostream>

using namespace std;

int main ()
{
LOOP:char n[]={'a','e','i','o','u','\0' };
char f;

cout << "Please enter a letter" << endl;
cin >> f;

if (f==n[]) //error here
{
cout << "Vowel" << endl;
}

else {
cout << "Consonant" << endl;

}

goto LOOP;
system("pause");
return 0;

}





please help...
you don't need to add the NULL '\0' character when initializing arrays, or in case you don't know, you can simply use :

char n[] = "aeiou";


~~~~~~~

you have to use a loop in order to check if the char entered has a match in the array
( and a temporary variable as a flag )
1
2
3
4
5
6
7
8
9
10
bool hasMatch = false;

for( int i = 0; i < 5; i++ ) {
    if( f == n[ i ];
        hasMatch = true;
}
if( hasMatch ) // same as hasMatch == true
    cout << "Vowel" << endl;
else
    cout << "Consonant" << endl;
Last edited on
Perhaps you haven't come across them yet (don't worry if you haven't) but you can also make use of the std::string class.

In this instance, you wouldn't need the loop at all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <cctype>
#include <string>

int main( int argc, char* argv[] )
{
    const std::string VOWELS = "aeiou";
    std::string phonetic = "consonant";
    char input;
    
    std::cout << "Please enter a letter: ";

    // Don't worry if this line looks weird, it's just making
    // sure the use enters a character.
    while( !( std::cin >> input ) || input < 'A' || input > 'z' )
    {
        std::cout << "\nInvalid input. Try again: ";
        std::cin.ignore( 256, '\n' );
        std::cin.clear();
    }

    // We can use find to look for a series of characters in a string
    // Note, we use tolower first as we've used lower case characters
    // in our constant VOWELS string above
    if( VOWELS.find( tolower( input ) ) != std::string::npos )
        phonetic = "vowel";

    std::cout << "Your letter is a " << phonetic << std::endl;
    return 0;
}


Edit: Removed superfluous brackets.
Last edited on
not working mate....:(....

anyways...thanx for the tip...!!!
What's not working? Post any changes you've made.

We'll get it working. :-)
thanx...ihutch105...i am really a beginner...an intermediate u cud say...
i hav no scope to learn programming in the area i liv in....so i am learning a bit with pdf books...

thanx...really...!!!
Change it to

if (f==n[0]||f==n[1]||f==n[2]||f==n[3]||f==n[4])
yes..tat's working too...sanddy1911....!!!
@ Messi001
iHutch105 code will work if you add

using namespace std;

or just add .h in each header files

1
2
3
#include <iostream.h>
#include <cctype.h>
#include <string.h> 
thanx....its working now....!!!!
Topic archived. No new replies allowed.