Hello. I am relatively new to C++ programming, and I have a question about a program that I am supposed to write. The assignment reads...
Prompt the user for a word; call it SEARCH. Then begin reading words from the user, counting them until SEARCH is entered. Display how many words were entered until the SEARCH word was found. Run the program first to see the expected output. Use a WHILE loop to do this.
This is what I wrote.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string search = "";
int count = 0;
cout << "Enter a search word: ";
do
{getline (cin, word);
count++;
}
while (search != "");
cout << count << endl;
}
I am not sure why this does not run. If I type in a word E.G. (while (search != "ok") it runs like it is supposed too, but the program the prof. uses randomly generates words, and the output is always 4. I do not see what I am doing wrong here. Any help is appreciated. Thank you!