/************************************
Write a program that reads in a char
target and a string test and tells the
user whether target was in test.
 ************************************/
#include <iostream>
#include <string>
using namespace std;

bool in(char c, string s);

int main()
{
  // Get targer char and test string
  char target;
  string test;
  cout << "Enter target char: ";
  cin >> target;
  cout << "Enter test string: ";
  cin >> test;
  
  // Print whether target in test
  cout << "Character " << target << " is ";
  if (!in(target,test))
    cout << "not ";
  cout << "in string " << test << endl;
  
  return 0;
}

// in(c,s) is a predicate that returns
// true if c is in s, and false otherwise.
// notice how it makes use of short-circuit
// evaluation, and boolean expressions!
bool in(char c, string s)
{
  int N = s.length(), i = 0;
  while(i < N && s[i] != c)
    i++;
  return i < N;
}