Help with writing a function
I am trying to write a function that will take input from the user and compare it to a list of valid entries.
Code:
#include <iostream.h>
char GetChoice(const String, &LegalChoices);
/*Forces the user to enter a character in LegalChoices and returns it
Post: Character in ValidChoices returned */
char *ValidChoices = "ABCabc";
char GetChoice(char *ValidChoices)
{
char Choice;
int cx;
int valid = FALSE;
while (!valid)
{
cout<<"Enter your choice (A, B, or C):";
cin>>Choice;
cx = 0;
while (ValidChoices[cx] != '\0')
{
if (Choice == ValidChoices[cx])
{
valid = TRUE;
break;
}
cx ++;
}
if (!valid) "Invalid Choice";
}
return Choice;
}
This is the code I am trying to use in the function. I am getting 3 errors:
Error in this line
Code:
char GetChoice(const String, &LegalChoices);
This line
and this line
I don't see what I am missing maybe because I have been staring at this for a few hours. Can someone point what I am doing wrong? Or if there is a better way for me to do this. i am using this in many sections of my code and I am just trying to make this easier then writing it multiple times.