Working on an assignment for C++ codding. Need a little help. I need to write a function that takes in the user's input and returns true if the input contains "polly", "cracker", or "hello".
Working on an assignment for C++ codding. Need a little help. I need to write a function that takes in the user's input and returns true if the input contains "polly", "cracker", or "hello". Thanks in advance!
#include <iostream>
using namespace std;
//Declare a function
bool check(string input);
int main()
{
//Declare the variable
string input;
cout<<"Enter input: ";
//Get user's input
cin>>input;
//Call the function and if it returns true
if(check(input))
cout<< "true";
else
cout<<"false";
return 0;
}
/*Define function that takes user's input and returns true
if the input contains "polly", "cracker", or "hello"*/
bool check(string input)
{
//Check if the input contains "polly", "cracker", or "hello"
if(input=="polly"|| input=="cracker" ||input=="hello")
return true;
else
return false;
}
Step by step
Solved in 3 steps with 5 images