954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

user defined function based on array

guys i need help ASAP since i need to submit this miniproject and i need 1 more minor questions need asnwered.

the C++ coding is given below, i need to change it to function type but giving out the same output.


#include
#define SIZE 7
using namespace std;

int main()
{

int A[ SIZE ] = { 2, 4, 8, 16, 32, 64, 128};
int i, j;
int total = 0;


cout <<"Value of array: ";
for ( j = 0; j

mikeblitz
Newbie Poster
2 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

First off, you need to edit your post so that the code is in [CODE] tags - the forum software does not retain indentation, so the code is unreadable unless you use the tags.

Second, just what do you mean you need to 'change it to function type'? Do you need to break the program into more than one function, or what?

Schol-R-LEA
Posting Pro
556 posts since Oct 2010
Reputation Points: 254
Solved Threads: 85
 

well it is kinda complicated (to me)

but heres the actual question


Modify the program in Figure 1 below to include a user-defined function. The output of the modified program must be same.

mikeblitz
Newbie Poster
2 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Try taking the second for() loop out of the main() function, and put it into a new function starting with the line:

int sum(int* A)

and after the end of the for() loop, add a line

return total;


Now, where the for() loop was, put the following line:

total = sum(A);

This will actually call the function you've written.

Schol-R-LEA
Posting Pro
556 posts since Oct 2010
Reputation Points: 254
Solved Threads: 85
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: