0

failed build for my project

A message of (control may reach end of non-void function) why? here Is my code : int search(book x[], int size , string name){ for(int=0 ; i<size ; i++) if(name.compare(x[i].nameOfbook)==0) return i; }

9th Apr 2020, 7:19 PM
superNOVA
superNOVA - avatar
1 Answer
+ 2
What if the if block never true.. For that You shloud add return statement as last statement return -1; //for search unsuccessful.... So correct code: int search(book x[], int size , string name){ for(int=0 ; i<size ; i++) if(name.compare(x[i].nameOfbook)==0) return i; return -1; }
9th Apr 2020, 7:27 PM
Jayakrishna 🇼🇳