954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

please help

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;
}
angelfox
Newbie Poster
4 posts since Aug 2007
Reputation Points: 6
Solved Threads: 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.

Boldgamer
Light Poster
44 posts since Dec 2006
Reputation Points: 11
Solved Threads: 2
 

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++.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

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

angelfox
Newbie Poster
4 posts since Aug 2007
Reputation Points: 6
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You