Error in c++ function code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

18th Nov 2019, 11:45 PM
wojod
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 👍
19th Nov 2019, 12:34 AM
Ipang
+ 2
You're welcome : )
19th Nov 2019, 1:56 AM
Ipang
+ 1
thank you so much !!!
19th Nov 2019, 12:38 AM
wojod
+ 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 :)
19th Nov 2019, 7:45 AM
Jakub Stasiak
Jakub Stasiak - avatar