New course! Every coder should learn Generative AI!
Try a free lesson0
Error in c++ function code
bool validclass (char) { bool valid=true ; if (char =='F' ||char = 'B'||char ='E' ){ valid = true ; } else if { valid = false ; } return valid ; } The error message was Expected primary expression before ‘char’ Expected ‘)’ before char Expected ‘(‘ before ‘{‘token
4 Answers
+ 4
Avoid using type name for variable or function name, you risk confusing yourself over time.
******************************
bool validclass (char)
'char' is a type name. You should specify a parameter name following the type name; as follows:
bool validclass(char c)
******************************
if(char =='F' ||char = 'B'||char ='E')
Here you use '=' to compare against 'B' and 'E' while you should do as you did to compare against 'F'
if(c == 'F' || c == 'B'|| c == 'E')
******************************
else if
Your `else if` statement here is invalid; because there is no condition to evaluate and conclude whether the condition satisfies. I believe you meant to use `else` instead.
I Suggest you to review the lesson to get better understanding 👍
+ 2
You're welcome : )
+ 1
thank you so much !!!
+ 1
Also you could shorten your code to:
return (c == 'F' || c == 'B' || c == 'E')
No need for setting another variable and use of ifs :)