Question about execution

This is a discussion on Question about execution within the C++ Programming forums, part of the General Programming Boards category; My program works.... but when I execute it, and input the sentence, I have to push enter twice in order ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    75

    Question Question about execution

    My program works.... but when I execute it, and input the sentence, I have to push enter twice in order for the rest of the program to execute. What do I need to change so that I only have to push enter once for the rest to follow through?

    Code:
    #include <iostream>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    int isVowel(string mystring);
    
    
    int main()
    {
    	string vowelcheck;
    	cout << "Enter a sentence: " << endl;
    	getline(cin, vowelcheck, '\n');
    	cout << "There are " << isVowel(vowelcheck) << " vowels in this sentence." << endl;
    	return 0;
    }
    
    int isVowel(string mystring)
    {
    	int numvow = 0;
    	transform (mystring.begin(), mystring.end(), mystring.begin(), tolower);
    	string::iterator forward;
    	for(forward = mystring.begin(); forward != mystring.end(); forward++)
    	{
    		if(*(forward) == 'a' || *(forward) == 'e' || 
    			*(forward) == 'i' || *(forward) == 'o' || *(forward) == 'u' )
    		{
    			numvow++;
    		}
    	}
    	return numvow;
    }

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    I saw this in your other thread, but I didn't touch it because you're using non-standard functions... that may be the source of your problem... see below:
    Code:
    #include<iostream>
    #include<string>
    //#include<algoritm>    //my guess is to include transform?
    
    using namespace std;
    
    int isVowel(string mystring);
    
    
    int main()
    {
            string vowelcheck;
            cout << "Enter a sentence: " << endl;
            getline(cin, vowelcheck, '\n');
            cout << "There are " << isVowel(vowelcheck) << " vowels in this sentence." << endl;
            return 0;
    }
    
    int isVowel(string mystring)
    {
            int numvow = 0;
            //transform (mystring.begin(), mystring.end(), mystring.begin(), tolower);      //non-standard function (AFAIK)
    
            int l=mystring.length();        //returns the length of the string
            char ch;                        //to hold the individual characters of the string
            for(int i=0;i<l;i++)            //loop through each character in the string
            {
                    ch=mystring.at(i);      //get the character from the string
                    ch=toupper(ch);         //change it to upper-case (upper-case letters have lower
                                            //ascii values than do lower-case letters, not that it
                                            //matters at all.
                    if( ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' )     //check to see if it's a vowel
                    {
                            numvow++;       //if it is, increase the count
                    }
            }
            return numvow;                  //return the number of vowels in the string
    }
    Last edited by major_small; 07-10-2005 at 10:56 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    Um I add a cin.get(); before return 0 in your code then compiled on devc++ and got an error because there is no such thing as transform...So the code is not portable, then in VS.net it compiled and I only had to push enter once after it found the vowels...must be a bug on ur comp

  4. #4
    Banned
    Join Date
    Jun 2005
    Posts
    594
    what non standard about iterator, using a iterator
    is better then using that, it protect from going out of bounds.

    BTW this is a strange occurrence, no one else
    is having the problem with the having to press enter.
    Last edited by ILoveVectors; 07-10-2005 at 10:53 PM.

  5. #5
    *this
    Join Date
    Mar 2005
    Posts
    498
    Maybe your running it in debug mode? With some parameters or something.

  6. #6
    *this
    Join Date
    Mar 2005
    Posts
    498
    Quote Originally Posted by ILoveVectors
    what non standard about iterator, using a iterator
    is better then using that, it protect from going out of bounds.

    anyways and transform should be standard be cause the
    algorithm header is a standard header.

    BTW this is a strange occurrence, no one else
    is having the problem, wether compiled on .NET
    or devc++ which i tested it on both.
    It doesnt compile on the newest version of dev-c++

  7. #7
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Actually that is correct about transform,
    that was my mistake, but you can either
    convert the string tolower yourself,
    or you can just search for aeiouAEIOU

  8. #8
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by ILoveVectors
    what non standard about iterator, using a iterator
    is better then using that, it protect from going out of bounds.
    I didn't mean the iterator was non-standard. the function was. I just chose not to use an iterator...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  9. #9
    Banned
    Join Date
    Jun 2005
    Posts
    594
    ah ok, sorry i get defensive, when its my code lol.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    The problem is probably a bug in your compiler because the OP's posted code is correct and well written. There is a bug in VC++ 6 that makes you hit enter twice, see the following site and scroll to the <string> fix: http://www.dinkumware.com/vc_fixes.html

    Everything in the code is standard from what I see, except potentially for the interpretation of what a vowel is.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. Execution Time - Rijandael encryption
    By gamer4life687 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2008, 09:25 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21