You declare is_valid as true just before you use it as argument. That means that argument will always hold the value true, wich makes there is no need to use it as parameter. You can also declare that value inside the function itself.
The problem with the above code is that you pass the variable is_valid to the function, while you should use a pointer to that variable as argument.
You dont do anything with the value CheckInput returns. There is no need to use complex pointers here, but if you do, make the type of CheckInput void.
This is the solution i would recommend:
Use this as the function CheckInput:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
bool CheckInput (string input){
//local variables:
bool is_valid=false;
string weekDay[7]={"Monday","Tuesday",...}
//check or the input is correct
for (int i=0;i<=6;i++){
if (input==weekDay[i]{
is_valid=true; //set is_valid to true if the input is correct:
//when the input is incorrect this wont happen and is_valid would stay false
break;
}
}
return is_valid; //return true if the input is correct, else false
}
|
Then you should call it like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
string userChoose; //try to avoid the same name for different local variables
bool correctChoose;
cout<<"Enter a day of the week:\n";
cin>>userChoose;
correctChoose=CheckInput(userChoose); //store the value returned by the function into correctChoose
if (correctChoose){
//do what you want to do if input is correct
}
else
{
//do what you want to do if input is incorrect
}
|
I havent tested those codes, there may be some mistakes in it.
Hope you understand the above codes. It is more important that you understand how it works then that it works. Please ask if you got questions