The function I have written is an attempt to return true if all elements in an array are positive and false otherwise. When I run it it keeps running it as true even though I have one negative number in the array. And depending on what code adjustments I make I get a warning that says:
I know it has something to do with me not setting up a condition if an array element happens to be negative but i thought the return false if not true statement took care of that. Any help is always appreciated.Code:warning C4715: 'pos' : not all control paths return a value
Code:#include <iostream> using namespace std; bool pos(int a[],int size );//prototype int main() { const int size=10; int a[size]={1,2,3,4,5,6,-7,8,9,10}; cout<<"All elements in array are positive"; cout<<pos(a,size);//call return 0; } bool pos(int a[], int size) //print number of even elements { for(int i=0;i<size;i++){ if((a[i]%2)==0) return true; else { return false; } } }



LinkBack URL
About LinkBacks



There's a few other things you need to check up on too, the first being your indentation. Ouch, you code is hurting my eyes! lol... nothings lined up or anything. Anyhoo, here goes...