- #1
ZakAttk1
- 7
- 0
I have an assignment for my CS class.
It is the following:
*
* complete the function:
*
* timesFound(string searchIn, char searchFor);
*
* The function should return the number of times the
* character searchFor appears in the string searchIn.
*
*/
int timesFound(string searchIn, char searchFor)
{
}
int main()
{
string textLine;
char findThis, response = 'y';
bool running = true;
while (running)
{
cout << "Please enter a line of text: ";
getline(cin, textLine);
cout << "Please enter the character to search for: ";
cin >> findThis;
cout << "The search character was found " << timesFound(textLine, findThis) << " times.\n";
cout << "Would you like to continue? (y/n) ";
cin >> response;
while (response != 'n' && response != 'y')
{
cout << "Would you like to continue? (y/n) ";
cin >> response;
}
if (response == 'n')
running = false;
else
cin.ignore();
}
}
As always I know what the program is supposed to do, but I am lost on how to start. Any help is appreciated. Thank you
It is the following:
*
* complete the function:
*
* timesFound(string searchIn, char searchFor);
*
* The function should return the number of times the
* character searchFor appears in the string searchIn.
*
*/
int timesFound(string searchIn, char searchFor)
{
}
int main()
{
string textLine;
char findThis, response = 'y';
bool running = true;
while (running)
{
cout << "Please enter a line of text: ";
getline(cin, textLine);
cout << "Please enter the character to search for: ";
cin >> findThis;
cout << "The search character was found " << timesFound(textLine, findThis) << " times.\n";
cout << "Would you like to continue? (y/n) ";
cin >> response;
while (response != 'n' && response != 'y')
{
cout << "Would you like to continue? (y/n) ";
cin >> response;
}
if (response == 'n')
running = false;
else
cin.ignore();
}
}
As always I know what the program is supposed to do, but I am lost on how to start. Any help is appreciated. Thank you