tiny question

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.


the function returns the summation of the elements in the 2 diagonals of the array, otherwise it returns -1.

Yes
so if i'm required to use function the code will look like this ?



int main()
{
function call (......)
}


other_function(.......)
{
if (even)
return -1
else
return sum
}

Yeah

If its even, return -1 otherwise return the result.
return function call (.....)

Yeah as Texan40 said, remember that your function should return a value so it should be declared as such. :)
texan 40

do u mean that i have to write my function call on the main return like this ?


int main()
{
return function call (......)
}

Yes, that's what I mean.
thanks a lot :))
1
2
3
4
int main()
{
return function call (......)
}

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.
}
Topic archived. No new replies allowed.