please help

Reply

Join Date: Aug 2007
Posts: 4
Reputation: angelfox is an unknown quantity at this point 
Solved Threads: 0
angelfox angelfox is offline Offline
Newbie Poster

please help

 
0
  #1
Aug 29th, 2007
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


  1. #include<iostream>
  2. using namespace std;
  3.  
  4. char vowels[]={a,e,i,o,u};
  5. char n;
  6.  
  7. char main()
  8. {
  9. cout<<“Please Enter a Character:\n”;
  10. cin>>n;
  11. {
  12. if (n=vowels)
  13. cout<<“n is a VOWEL\n”;
  14. else
  15. cout<<“n is CONSONANT\n”;
  16. }
  17. return 0;
  18. }
Last edited by WolfPack; Aug 29th, 2007 at 12:13 pm. Reason: ADDED [CODE=CPP][/CODE] TAGS
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 44
Reputation: Boldgamer is an unknown quantity at this point 
Solved Threads: 2
Boldgamer's Avatar
Boldgamer Boldgamer is offline Offline
Light Poster

Re: please help

 
0
  #2
Aug 29th, 2007
I am a begginer also but I believe you need main to be declared as
  1. int main()
The line
  1. char vowels[]={a,e,i,o,u};
isn't needed.
I would put
  1. char n;
inside int main().
For your branching statement you would declare each of the vowels in the condition statement i.e.
  1. if (n == 'A' || n== 'a' || n == 'E' || ect...)
It would probably be a lot easier to use a switch statement though. i.e.
  1.  
  2. switch (n)
  3. {
  4. case 'A':
  5. case 'a':
  6. case 'E':
  7. case 'e':
  8. case 'I':
  9. case 'i':
  10. case 'O':
  11. case 'o':
  12. case 'U':
  13. case 'u':
  14. {
  15. cout << "This letter is a Vowel." << endl;
  16. break;
  17. }
  18. default:
  19. {
  20. cout << "This letter is a consonant." << endl;
  21. }
  22. }
Only problem with this is that if someone enters something that is not an alphabet it will be considered a consonant.
Last edited by Boldgamer; Aug 29th, 2007 at 12:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,671
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: please help

 
0
  #3
Aug 29th, 2007
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++.
Last edited by Lerner; Aug 29th, 2007 at 12:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 4
Reputation: angelfox is an unknown quantity at this point 
Solved Threads: 0
angelfox angelfox is offline Offline
Newbie Poster

Re: please help

 
0
  #4
Aug 30th, 2007
thank you so much for your help... it really helps in understanding some of the concepts..... and their functions.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC