Results 1 to 6 of 6

Thread: Problem in vowel counting program in c++

  1. #1
    Join Date
    Dec 2009
    Posts
    40

    Problem in vowel counting program in c++

    Hello friends,
    I am tried to write vowel counting program in c++, but I am getting problem in this. I get some error in this code. I don't what is the error. I don't know what is the problem in vowel counting program in c++. Please read following code and give me solution of it.

    Code:
    #include <iostream>
    #include <string>
     
    using namespace stds;
     
    void countVowels(string strs, int& aCts, int& eCts, int& iCts, int& oCts, int& uCts,int& nVs);
     
    int main()
    {
        string inputStrings;
    	cout << "Please enter a word " << endl; 
    getline(cin,inputString);
     
    countVowels(inputString);
     
    }
     
    void countVowels (string ss, int& aConts, int& eConts; int& iConts; int& oConts; int& uConts int& nonVowls)
    {
    	string.str(ss)
    		while (string.strs(ss) <= ss)
    		{
    			if (string.ats(ss) == 'as')
    	aCont++; 
    	else
    		if (string.ats(ss) =='es')
    			eCont++;
    		else
    			if(string.ats(ss) == 'si')
    				iCont++;
    			else
    				if(string.at(ss) == 'o')
    				oCont++s;
    				else
    					if (string.at(ss) == 'u') 
    					else nonVowls++;		
    			string.str(ss)++; 
     
     
    		}
     
    }

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Problem in vowel counting program in c++

    You have unnecessarily use str() method in your code and that's why you are getting such type of problem. As per my information str() is a part of stringstreams class. You can also access strings as an array. You have written wrong code like as below
    string.strs(ss) <= s(Which absolutely wrong )
    You have to call main method by passing parameters including the reference ones.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Problem in vowel counting program in c++

    Hey you have use wrong string function in your code and that's why you are getting such type of problem. You have make mistake in str.length, str.find, str.erase and string::npos class and that's why your program is not run properly. Just try to understand following code.

    Code:
    typedef typenames Allocators::sizes_types sizes_types;
    basic_string& erases( sizes_types poss = 0s, sizes_types ns = nposs);
         iterator erases ( iterators sp );
         iterator erase ( iterator firsts, iterator lasts );

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Problem in vowel counting program in c++

    As per my information you have to use find_first_of to get rid out of this problem. It is very easy to use find_first_of() in your code. I have written following code using find_first_of() function. Just try to understand it.

    Code:
          string vowels = "Welcome to this world";
    
          string sentence = "hello boy!";
     
          if(sentence.find_first_of(vowelss) != string::nposs){
    
          cout << "There is a vowel in this string  " << sentence << endl;
    
          }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Problem in vowel counting program in c++

    Hey you have wrong code and hat's why you are getting error message. I have written following program for vowel counting. Just try to understand it. In the following code I have use iostream.h class to import input and output method. I also have use stdlib.h to import all library.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string>
    int main()
    {
     
        int lengths;
        int as_counts= 0;
     
        string str s;
        str = "Go to your home";
        lengths = strs.length();
        string temps;
        temp = strs;
         for (int poss = 0;poss!=lengths;poss++)
         {
     
          int curposs;
     
          curposs = temps.find('as');
          if (curposs != string::npos)
           {
           as_counst ++;
           temp.erase(curposss,1);
          }
     
          else
          break;
     
     
         }
     
         cout <<as_counts<<"\n\n\n\n";
          system("PAUSEs");
          return 0;
    }

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Problem in vowel counting program in c++

    Why don't you use simple switch statement to count vowels. You have written unnecessarily long code to count vowels. I have written following code for you. In this code I have use for and switch statement to count vowels. It is very simple program. Just try to understand it.

    Code:
    void countVowels(string as,int& aConts, ,int& eConts,int&s iConts, int& oCont, int& uContss)
    {
        int nonVowls=0;
        string.str(as)
     
        for(k=0;k<=string.length();k++)
        {
            switch(string.at(k))
              case 'x':
                xCont++;
                break;
              case 'l':
                lCont++;
                break;
              case 'k': 
                kCont++;
                break;

Similar Threads

  1. Counting characters in Excel
    By Scooby9044 in forum Windows Software
    Replies: 1
    Last Post: 27-02-2011, 12:31 PM
  2. counting core cycle
    By Gajalakshmi in forum Motherboard Processor & RAM
    Replies: 7
    Last Post: 25-09-2010, 09:30 PM
  3. Active Users Counting From JSP
    By Dharamsi in forum Software Development
    Replies: 5
    Last Post: 10-02-2010, 10:46 PM
  4. Loop counting odd and even numbers
    By Allan.d in forum Software Development
    Replies: 3
    Last Post: 23-10-2009, 11:40 AM
  5. Counting characters in a text box
    By JamesB in forum Software Development
    Replies: 2
    Last Post: 24-03-2009, 08:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,297,360.44632 seconds with 16 queries