# Counting Vowels From Line With a Function Statement (NO POINTER)

Page 1 of 1

## 9 Replies - 3218 Views - Last Post: 13 October 2010 - 04:06 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=194820&amp;s=cf4a016136460239b8dc5291692d82d5&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 CodingInTheory

Reputation: 0
• Posts: 5
• Joined: 13-October 10

# Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 10:05 AM

Hello Everybody

I am having trouble using a function statement in order to count vowels in an input statement here is a detailed description on what the program is intended to do:

1) Get line from user (ex. hi, this is a sentence.)
2) Program must recognize every vowel in the input sentence and count.
3) Must be done using some kind of loop and a function statement.
+++(I was thinking of a for loop)++++
4) Must total up every vowel found in the input sentence and out put data

Here is what I have so far, any suggestions will be greatly appreciated. Thank You

```#include <iostream>
#include <string>

using namespace std;

char vowels(char a, e, i, o, u);

int main()
{
string input;
int i;
char ch;

cout << "Please enter text: ";

getline(cin, input);

cout << "You entered: " << input << endl;

cout << "The string is " << input.length() << " characters   long." << endl;

for(i = 0; i < input.length(); i++)
cout << input[i];

cout << endl << endl;

return 0;
}

char vowels(char a, e, i, o, u)
{
char ch;
int vowelCounter = 0;

if (ch = vowels; vowelCounter++)
cout << input[i];

return vowelCounter;
}
```

Is This A Good Question/Topic? 0

## Replies To: Counting Vowels From Line With a Function Statement (NO POINTER)

### #2 Oler1s

• D.I.C Lover

Reputation: 1396
• Posts: 3,884
• Joined: 04-June 09

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 10:18 AM

### #3 Aphex19

• Born again Pastafarian.

Reputation: 616
• Posts: 1,873
• Joined: 02-August 09

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 11:02 AM

You forgot the data specfiers in each parameter.

```char vowels(char a, e, i, o, u)
```

should be...
```char vowels(char a, char e, char i, char o, char u)
```

But, was that the problem?

### #4 CodingInTheory

Reputation: 0
• Posts: 5
• Joined: 13-October 10

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:07 PM

Oler1s, on 13 October 2010 - 09:18 AM, said:

My apologies for being to unclear previously. I have the program testing through and the program only counts the characters in the text. I need the program to count the vowels. How do I get my fucntion statement to count the vowels out of the for loop?
This is what I Have now.

```#include <iostream>
#include <string>

using namespace std;

char vowels(char a, char e, char i, char o, char u);

int main()
{
string input;
int i;
char ch;

cout << "Please enter text: ";

getline(cin, input);

cout << "You entered: " << input << endl;

cout << "The string is " << input.length() << " characters long." << endl;

for(i = 0; i < input.length(); i++)
cout << input[i];

cout << endl << endl;

return 0;
}

char vowels(char a, char e, char i, char o, char u)
{
char ch;
int vowelCounter = 0;
string input;

if (ch = a, e, i, o, u, vowelCounter++);
cout << input[i];

return vowelCounter;
}
```

### #5 aaa111

• D.I.C Regular

Reputation: 88
• Posts: 284
• Joined: 21-February 07

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:09 PM

Elaborate this:
```if (ch = a, e, i, o, u, vowelCounter++);
```

This post has been edited by aaa111: 13 October 2010 - 01:09 PM

### #6 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:12 PM

Create an array of vowels then search the line if vowel is true count++;

### #7 CodingInTheory

Reputation: 0
• Posts: 5
• Joined: 13-October 10

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:20 PM

Oler1s, on 13 October 2010 - 09:18 AM, said:

seeP+, on 13 October 2010 - 12:12 PM, said:

Create an array of vowels then search the line if vowel is true count++;

Thats what I'm trying to figure out how to do, but we have not learned them yet. The teacher said if we can figure out how to do an array with the program we would get xtra credit. Any pointers would help considerably, I have been looking in the C++ tutorials and grinding it out that way.

### #8 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:28 PM

Here is a great place to look if your textbook makes it complicated.
Arrays

Once you get that then its simply using a loop and decision statements to step through the string and count.

This post has been edited by seeP+: 13 October 2010 - 01:29 PM

Reputation: 31
• Posts: 139
• Joined: 01-October 10

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 01:30 PM

I know there is a function vowels. but where did you call that function?

Edit: nevermind, it was a stupid question.

This post has been edited by shad0wk1: 13 October 2010 - 01:31 PM

### #10 CodingInTheory

Reputation: 0
• Posts: 5
• Joined: 13-October 10

## Re: Counting Vowels From Line With a Function Statement (NO POINTER)

Posted 13 October 2010 - 04:06 PM

seeP+, on 13 October 2010 - 12:28 PM, said:

Here is a great place to look if your textbook makes it complicated.
Arrays

Once you get that then its simply using a loop and decision statements to step through the string and count.

Thanks alot, the link you gave me was very informative. The text book we are using is by D.S. Malik 5th edition, C++ and it does not give very good explanations towards program problems. Plus it lacks in detail when describing components of C++.