Write sentence, then return # of vowels - Need help, plz.

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 9
Reputation: KittyGirl is an unknown quantity at this point 
Solved Threads: 0
KittyGirl KittyGirl is offline Offline
Newbie Poster

Write sentence, then return # of vowels - Need help, plz.

 
0
  #1
Oct 24th, 2004
I have to write code that will prompt you to input a sentence, then it will output the number of vowels in the sentence. This is what I have so far. Can someone tell me what is wrong with it?

Thanks so much!

  1. //Input a sentence, then return number of vowels in the sentence
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. char ch(char vowel);
  6. char isVowel (char a, char e, char i, char o, char u);
  7.  
  8. int main ()
  9.  
  10. char sentence;
  11. char isVowel;
  12. int number;
  13. {
  14. cout<<"Enter a sentence"<<endl;
  15. cin>>sentence;
  16. cout<<"There are "<<number<<" vowels in this sentence."<<endl;
  17.  
  18. return 0;
  19.  
  20. }
  21. char isVowel (char a, char e, char i, char o, char u)
  22. {
  23. if (ch = 0)
  24. return number;
  25. else
  26. return false;
  27. }
Last edited by KittyGirl; Oct 24th, 2004 at 1:46 am. Reason: forgot [code] [/code]
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,817
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 747
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Write sentence, then return # of vowels - Need help, plz.

 
0
  #2
Oct 24th, 2004
>Can someone tell me what is wrong with it?
Just about everything. You're also overcomplicating things and it's pretty obvious that you aren't referring to any book on C++ or trying to compile this or you wouldn't have such dreadful syntax errors.

Use this as a template:
  1. #include <cctype>
  2. #include <iostream>
  3.  
  4. bool is_vowel ( int ch )
  5. {
  6. ch = std::tolower ( static_cast<unsigned char> ( ch ) );
  7. return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
  8. }
  9.  
  10. int main()
  11. {
  12. char ch;
  13. int vowels ( 0 );
  14.  
  15. std::cout<<"Enter a sentence: ";
  16. while ( std::cin.get ( ch ) && ch != '\n' ) {
  17. if ( is_vowel ( ch ) )
  18. ++vowels;
  19. }
  20.  
  21. std::cout<<"The number of vowels was: "<< vowels <<std::endl;
  22. }
But I should give you fair warning. If you copy parts of my code, you'll get a failing grade because it's written to make it obvious that you didn't come up with it on your own.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC