-
Ok, got an update here... still got a few errors.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string strInput;
cout << "\nPlease enter a gender specific sentence\n";
cout << "or enter `I'm done' to exit the program.\n";
getline(cin, strInput); //gets the user input
do
{
string::size_type loc = strInput.find("he", "him", 0);
if( loc = string::npos )
string strInput.replace("he", "he or she")||
string strInput.replace("him", "him or her")
cout << strInput;
else
cout << strInput;
}
while
(strInput != "I'm Done");
return 0;
}
}
Errors include:
- Error E2285 lab6.cpp 29: Could not find a match for 'string::find(char *,char *,int)' in function main()
- Warning W8060 lab6.cpp 31: Possibly incorrect assignment in function main()
- Error E2108 lab6.cpp 32: Improper use of typedef 'string' in function main()
- Warning W8004 lab6.cpp 39: 'loc' is assigned a value that is never used in function main()
Thanks for replying
-
We also weren't assigned a book for the class, so it's difficult to have to go to outside resources to find examples ofeverything. =(
-
if you want do process several statements inside if-block use
note that your strInput is not changed inside the loop, how do you plan to get the new input from the user?
-
Ok, still thats easy to fix, just move the do up...
Code:
int main()
{
string strInput;
do
{
cout << "\nPlease enter a gender specific sentence\n";
cout << "or enter `I'm done' to exit the program.\n";
getline(cin, strInput); //gets the user input
string::size_type loc = strInput.find("he", "him", 0);
if( loc = string::npos )
string strInput.replace("he", "he or she")||
string strInput.replace("him", "him or her")
cout << strInput;
else
cout << strInput;
}
while
(strInput != "I'm Done");
return 0;
}