944,200 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 733
  • C++ RSS
Aug 29th, 2007
0

please help

Expand Post »
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


cpp Syntax (Toggle Plain Text)
  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
Reputation Points: 6
Solved Threads: 0
Newbie Poster
angelfox is offline Offline
4 posts
since Aug 2007
Aug 29th, 2007
0

Re: please help

I am a begginer also but I believe you need main to be declared as
C++ Syntax (Toggle Plain Text)
  1. int main()
The line
C++ Syntax (Toggle Plain Text)
  1. char vowels[]={a,e,i,o,u};
isn't needed.
I would put
C++ Syntax (Toggle Plain Text)
  1. char n;
inside int main().
For your branching statement you would declare each of the vowels in the condition statement i.e.
C++ Syntax (Toggle Plain Text)
  1. if (n == 'A' || n== 'a' || n == 'E' || ect...)
It would probably be a lot easier to use a switch statement though. i.e.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 2
Light Poster
Boldgamer is offline Offline
44 posts
since Dec 2006
Aug 29th, 2007
0

Re: please help

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.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Aug 30th, 2007
0

Re: please help

thank you so much for your help... it really helps in understanding some of the concepts..... and their functions.
Reputation Points: 6
Solved Threads: 0
Newbie Poster
angelfox is offline Offline
4 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: school's back, and so am i :D
Next Thread in C++ Forum Timeline: Lexer- Tokenizer problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC