> How do I find a specific 'char' in an array in a function?

How do I find a specific 'char' in an array in a function?

Posted at: 2014-12-18 
How about something like this:

bool ReadOperator(const char Array[], char & b)

{

return (cin >> b) && strchr (Array, b) != NULL;

}

We read the next character from standard input. That's "cin >> b". If that fails, we want to fail even if b already contains a residual legitimate character from a previous call. If the input operation succeeds, we look for the character in the string of valid op chars using the good old fashioned easy-to-use "strchr".

write a function that reads in the operator and returns a boolean – true if the operator is valid, false if not valid. This function will have two parameters. First is a string of characters containing the valid operators. The second is a reference parameter where the operator will be placed if the operator entered is valid.

here is my code

I can't figure out how to set up the boolean function to check if the operator is either a + - * / C or X

[code]

#include

using namespace std;

#include "ReadInteger.h"

#include

#include // this also has in it to upper and tolower used below

#include // include stdlib.h if you are using exit in the code below

double Add(double, double);

double Subtract(double, double);

double Multiply(double, double);

double Divide(double, double);

bool ReadOperator(const char[], char &);

void main()

{

double num1;

char ValidOperators[] = "+-*/xXcc";

char Op;

bool ValidOp;

cout << "Enter first number " << endl;

num1 = ReadInteger(); //enter the first number

cout << "Enter operator " << endl;

do{

if (ReadOperator(ValidOperators, Op))

{

ValidOp = true;

cout << Op << " is a valid operator" << endl;

}

else

cout << "Not a valid operator" << endl;

ValidOp = false;

}

while (ValidOp != true);

}

bool ReadOperator(const char Array[], char & b)

{



[/code]