i know this is 2 easy for you guys, but please help..... Its been only 2 wks since i enrolled this class and they gave me this assignment.... please check if its correct. thank you so much

#include<iostream>
using namespace std;

char vowels[]={a,e,i,o,u};
char n;

char main()
{
cout<<“Please Enter a Character:\n”;
cin>>n;
{
if (n=vowels)
       cout<<“n is a VOWEL\n”;
else
       cout<<“n is CONSONANT\n”;
        }
return 0;
}

I am a begginer also but I believe you need main to be declared as

int main()

The line

char vowels[]={a,e,i,o,u};

isn't needed.
I would put

char n;

inside int main().
For your branching statement you would declare each of the vowels in the condition statement i.e.

if (n == 'A' || n== 'a' || n == 'E' || ect...)

It would probably be a lot easier to use a switch statement though. i.e.

switch (n)
    {
    case 'A':
    case 'a':
    case 'E':
    case 'e':
    case 'I':
    case 'i':
    case 'O':
    case 'o':
    case 'U':
    case 'u':
          {
              cout << "This letter is a Vowel." << endl;
              break;
          }
    default:
        {
            cout << "This letter is a consonant." << endl;
        }
    }

Only problem with this is that if someone enters something that is not an alphabet it will be considered a consonant.

Welcome to Daniweb. I see that Wolfpack helped formating your code since it was your first post. In the future please use code tags when posting information, like code, where you want to preserve indentation.

As another alternative you could use the array and a loop to read through array to check if the given char is a vowel or not. Of course this assumes you know about accessing elements of an array and control loops, etc.

Note how Boldgamer refers to single chars using single quotes before and after the char, and how Bolgamer used the == operator rather than the = operator for equals.

Trying to avoid global variables is considered good form in standard C++.

thank you so much for your help... it really helps in understanding some of the concepts..... and their functions. :)

This article has been dead for over six months. Start a new discussion instead.