hey everyone,
am i required to use function other than main in this question or return this values in main ? (I've already solve it)
Write a C++ program that takes a NxN 2-dimensional square
array of integers. If the summation of all array elements is odd, the function returns the
summation of the elements in the 2 diagonals of the array, otherwise it returns -1.
How will you know what was returned from main? Also, on some UNIX systems, only the least significant 7 bits of the return code are actually returned to the parent process. I think you may want: cout << function_call(...) << '\n';
instead.
You need to declare the function as such to define its return type.
In this example my function returns an integer, the type is declared before someFunction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
int someFunction();
int main()
{
int result;
result = someFunction();
std::cout << result;
return 0;
}
int someFunction()
{
return 255; // just some example.
}