Hi, this is my c++ code and I am confused on how to fix this error in my code an
ID: 3790811 • Letter: H
Question
Hi, this is my c++ code and I am confused on how to fix this error in my code and I'm curious if it's an easy solution or is it a fundemental problem with my code. Thank You!
And I get this error.
EDIT: I ended up figuring out how to fix the code (by changing the "string" type to an "int" type in the function), but is there anyway to reduce the "int main()" function down to just one line? Or am I going to have to have those two variables delcared int he main function for my program to work?
EDIT: Actually, at this moment, the program will only run once. As I type in "g++ Dubois,ChristopherHW3.cpp" and press enter; it'll be fine. But as I go into type "./a.exe"---no characters come up and Cygwin seems to "Freeze" up and I have to exit Cygwin in order to run the program again. Any reason for this?
EDIT: Here is the code. I figured the images would be enough
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int first_and_only_function(string Entered_Word, string Another_Word)
{
vector <string> NumberofWords;
string Key_Word_Needed = "*endl*";
int word_count = 0;
int Number_Of_Times = 0;
string new_Entered_Word;
string New_Another_Word;
while(true)
{
cout<<"Please Enter a search word (Terminating word is '*endl*'. ";
getline(cin,new_Entered_Word);
if ((Key_Word_Needed.compare(new_Entered_Word)==0))
{
break;
}
NumberofWords.push_back(new_Entered_Word);
word_count++;
}
cout<<"The amount of tries were: "<<word_count+1 << "(including correct search word) ";
cout<<"Let's find the number of times the word you'd like to find comes up! ";
cout<<"So, if you wanted to find out how many times 'bear' came up, just type in 'bear' again to see. ";
getline(cin,New_Another_Word);
for(int i=0; i<=word_count;i++)
{
if(NumberofWords[i].compare(New_Another_Word)==0)
{
Number_Of_Times++;
}
}
cout<<"The word came up:"<<Number_Of_Times<<" times in the list. ";
return(0);
}
int main()
{
string Entered_Word;
string Another_Word;
first_and_only_function(Entered_Word, Another_Word);
// return(0);
}
Explanation / Answer
for (i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.