count number of words starting with vowel

we have to count the number of words starting with vowel

Page 1 of 1

2 Replies - 7177 Views - Last Post: 03 January 2011 - 08:33 AM Rate Topic: **--- 2 Votes

#1 sreeram94  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-January 11

count number of words starting with vowel

Posted 03 January 2011 - 08:20 AM

help me in this program or atleast give hint .

i want to find the number of words starting with vowel but it still gives the output as number of words there in given string.
but i need only to find number of words starting with vowel :helpsmilie: :gun_bandana:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
	clrscr();
	char A[30],a,e,i,o,u;
	cout<<"input string : ";
	gets(A);
	int n=0;
	for(int j=0;A[j]!='\0';j++)
	{
	 if(A[j]==' ' && A[j+1]!=' ')
	 {
	  n++;
	 }
	}
	if(A[j]==a,e,i,o,u)
	{
	 cout<<n+1;
	}
	 getch();
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 03 January 2011 - 08:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: count number of words starting with vowel

#2 newclearner  Icon User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • Posts: 302
  • Joined: 29-September 10

Re: count number of words starting with vowel

Posted 03 January 2011 - 08:28 AM

1. Post your code in code tags.
2. Use indentation in your code.
3. Does you code compile. I doubt it. what's this:
if(A[j]==a,e,i,o,u)
4. Have you written this code yourself? I again doubt it. Because if you have written this code yourself you must know that this code is written for counting all the words not the one starting with vowels.
5. Even is you fix this line
if(A[j]==a,e,i,o,u)
if loop will never execute because after the for loops ends, j is pointing to '\0'. So your cout statement would never execute and you would see no output on screen.

This post has been edited by newclearner: 03 January 2011 - 08:30 AM

Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,606
  • Joined: 23-August 08

Re: count number of words starting with vowel

Posted 03 January 2011 - 08:33 AM

Let's count the things wrong with this code.

1. It's written for Turbo C++, which is a 20-year-old compiler for a 20-year-old operating system. It therefore uses non-standard functions and headers. Your school is cheating you. READ ME
2. void main() is ALWAYS WRONG in C++. It's int main(). PERIOD!!! Again, typical of what you're being taught. READ ME...from the CREATOR of C++.
3. gets() should NEVER be used. It is unsafe. READ ME.
4. You're using C I/O (and some C++ as well...don't mix these!) in a C++ program. READ ME
5. char a,e,i,o,u; does NOT create variables with those characters. It creates five variables NAMED with those characters that contain who knows what.
6. if(A[j]==a,e,i,o,u)...you CANNOT compare variables this way. Each one must be an explicit condition.

Answers:
1. Complain to your teacher and school that you're being cheated by being taught non-standard 20-year-old technology.
2. Go back to your books and read about variables.
3. Go back to your books and read about if statements and compound boolean conditions.

This post has been edited by JackOfAllTrades: 03 January 2011 - 08:37 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1