Write a progam that reads a string and outputs the number of times each
lowercase vowel appears in it. Your program must contain a function with one
of its parameters as a string variable and return the number of times each
lowercase vowel appears in it. Also write a program to test your function. (Note
that if str is a variable of type string, then str.at(i) returns the character
at the ith position. The position of the first character is 0. Also, str.length()
returns the length of the str, that is, the number of characters in str.)
Can someone tell me whats wrong with my code?
please?
Your program won't compile as posted.
Line 15: "to count a's" Is that a cut and paste error, or a comment?
Line 30: Your function name does not match your forward declaration. That is causing undefined references in the linker.
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
What is your question regarding the latest code you posted? This is not the same program as in yoor original post.
You have been asked to use code tags. PLEASE DO SO. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I will not respond further until you apply code tags.
#include <iostream>
#include <string>
usingnamespace std;
int vowelsNumberof (string, char);
int main()
{
string str;
cout << "Enter a string :" << endl; cin >> str; //Input string
cout << "The number of a's:" << vowelsNumberof (str, 'a') << endl;
to count a's
cout << "The number of e's:" << vowelsNumberof (str, 'e') << endl;
cout << "The number of i's:" << vowelsNumberof (str, 'i') << endl;
cout << "The number of o's:" << vowelsNumberof (str, 'o') << endl;
cout << "The number of u's:" << vowelsNumberof (str, 'u') << endl;
system ("pause");
}
int vowelsNumbersof(string str, char vowel)
{
int i, count = 0;
for(i=0; i < str.length(); i++)
if(str.at(i) == vowel)
count++;
return count;
}