Help?

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?

#include <iostream>
#include <string>

using namespace 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;
}
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.


#include "iostream"
using namespace std;

int main()
{
long int a = 1, b = 1, c = 1, n;

cout << "\n Ingrese un valor limite mayor que cero para mostrar los numeros de Fibonacci menores o iguales a el:\t";
cin >> n;

while (n < 0)
{
cout << "\n El numero ingresado no es valido. Ingrese un numero natural:\t";
cin >> n;
}

cout << "\n Los numeros de Fibonacci menores o iguales a " << n << " son:\n 1 ";

while (c <= n)
{
cout << " " << c << " ";
c = a + b;
a = b;
b = c;
}

cout << "\n\n ";


system("pause");


cpp.sh/9yp
i posted the link
cpp.sh/9yp
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.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
 #include <string>
 
using namespace 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;
 } 

 
You still have exactly the same problems I pointed out before.

Line 15: What is this?

Line 30: Your function name does not match your forward declaration. That is causing undefined references in the linker.
1
2
int vowelsNumberof (string, char); 
int vowelsNumbersof(string str, char vowel) 

Do you see the difference? A forward declaration and it's implementation must match exactly.






Topic archived. No new replies allowed.