Code:
#include <iostream>
const int MIN_ELEMENTS = 5;
typedef int ArrayType[MIN_ELEMENTS];
typedef int ElementType;
bool findSum( ArrayType myArray[], int n )
{
ElementType firstFiveSum = 0;
bool isSuccess = true;
if( n < MIN_ELEMENTS )
{
isSuccess = false;
}
else
{
for( int index = 0; MIN_ELEMENTS > index; ++index )
{
if( !( myArray[index] < 0 ) )
{
firstFiveSum += (ElementType)myArray[index];
}
else
{
isSuccess = false;
firstFiveSum = 0;
break;
}
}
}
std::cout << firstFiveSum << "\n";
return isSuccess;
}
int main()
{
const int FIRST_ARRAY_SIZE = 7;
const int SECOND_ARRAY_SIZE = 3;
ArrayType myFirstArray[FIRST_ARRAY_SIZE] = {1,1,1,1,1,1,1};
ArrayType mySecondArray[SECOND_ARRAY_SIZE] = {1,1,1};
findSum( myFirstArray, FIRST_ARRAY_SIZE );
return 0;
}
I couldn't find the error, can you?
Thanks in advance.