Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3042

Help with Vector input/couting

$
0
0
Hello, I am 3/4 weeks into programming curriculum, so this should be a relatively easy question! I am trying to write a program that counts specific words that a user inputs "Howdy/howdy/Whoop/whoop" (yes I go to Texas A&M, hence those specific words haha;) ) I am having an issue where it wont count the first word even if it is "Howdy"

For example if I put it:

"Howdy howdy whoop Whoop" - it only outputs that it counted 3 words

now if I were to do:

"Hello Howdy howdy whoop Whoop" - it would count 4.

Where did I go wrong? Thank you for any help!!

Code:

//Jordan Lewallen
//ENGR 112 - 512
//February 4, 2014
//hw2pr3.cpp

#include "std_lib_facilities_4.h"

int main(){
       
        cout << "Please enter desired words, when you have entered all words, please type CTRL+d (EOF Command)\n" << endl;
        //It was assumed that EOF command was going to be used here hence the necessity of 'CTRL+d'
       
        vector<string>words;
                string the_word;
                cin >> the_word;  //when the desired words are entered, the if loop will catch those and enter them into the vector
                while (cin >> the_word)
                if (the_word == "Whoop" || the_word == "whoop" || the_word == "Howdy" || the_word == "howdy"){
                        words.push_back(the_word); //pushing the words into vector
                        }
                cout << "Number of desired words: " << words.size() << endl; //displays the number of specific words that needed to be counted

                return 0;
}


Viewing all articles
Browse latest Browse all 3042

Trending Articles