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

Using function to count vowels in an input statement.

Page 1 of 1

9 Replies - 2529 Views - Last Post: 13 October 2010 - 04:06 PM Rate Topic: -----

#1 CodingInTheory  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • 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

What exactly is your question?
Was This Post Helpful? 0
  • +
  • -

#3 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 615
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#4 CodingInTheory  Icon User is offline

  • New D.I.C Head

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

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

Posted 13 October 2010 - 01:07 PM

View PostOler1s, on 13 October 2010 - 09:18 AM, said:

What exactly is your question?


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;
}

Was This Post Helpful? 0
  • +
  • -

#5 aaa111  Icon User is offline

  • D.I.C Regular

Reputation: 88
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#6 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • 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++;
Was This Post Helpful? 1
  • +
  • -

#7 CodingInTheory  Icon User is offline

  • New D.I.C Head

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

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

Posted 13 October 2010 - 01:20 PM

View PostOler1s, on 13 October 2010 - 09:18 AM, said:

What exactly is your question?


View PostseeP+, 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.
Was This Post Helpful? 0
  • +
  • -

#8 seeP+  Icon User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • 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

Was This Post Helpful? 1
  • +
  • -

#9 shad0wk1  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#10 CodingInTheory  Icon User is offline

  • New D.I.C Head

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

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

Posted 13 October 2010 - 04:06 PM

View PostseeP+, 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++.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1