| | |
Write sentence, then return # of vowels - Need help, plz.
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 9
Reputation:
Solved Threads: 0
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!
Thanks so much!
C++ Syntax (Toggle Plain Text)
//Input a sentence, then return number of vowels in the sentence #include <iostream> using namespace std; char ch(char vowel); char isVowel (char a, char e, char i, char o, char u); int main () char sentence; char isVowel; int number; { cout<<"Enter a sentence"<<endl; cin>>sentence; cout<<"There are "<<number<<" vowels in this sentence."<<endl; return 0; } char isVowel (char a, char e, char i, char o, char u) { if (ch = 0) return number; else return false; }
Last edited by KittyGirl; Oct 24th, 2004 at 1:46 am. Reason: forgot [code] [/code]
>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:
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.
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:
C++ Syntax (Toggle Plain Text)
#include <cctype> #include <iostream> bool is_vowel ( int ch ) { ch = std::tolower ( static_cast<unsigned char> ( ch ) ); return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'; } int main() { char ch; int vowels ( 0 ); std::cout<<"Enter a sentence: "; while ( std::cin.get ( ch ) && ch != '\n' ) { if ( is_vowel ( ch ) ) ++vowels; } std::cout<<"The number of vowels was: "<< vowels <<std::endl; }
New members chased away this month: 3
![]() |
Similar Threads
- events in counting vowels (C#)
- Could somebody write code for my project plz... (Visual Basic 4 / 5 / 6)
- Problems working with strchr (C++)
- i have problem with array plz help (Java)
- Return Length of a string? (C++)
Other Threads in the C++ Forum
- Previous Thread: loop problem
- Next Thread: functions
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






