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".

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 22SA
icon
Related questions
Question

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!

Expert Solution
Step 1: Program

#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 2: Screenshot

Computer Science homework question answer, step 2, image 1

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning