Function prototype

write the program with fuction prototype,calling and definition.Fuction should return sum and quantity of those array element that are less than X.FUcktion mucst take argument.EX:Let A(2,3,1,8,3,9,3,6,2,6),X=5..Answer is sum=14,quantity=6..Plz who can help me solve this solution now
http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/arrays/

Hint: a function can return only one value, but function can pass more information to the caller via non-const by reference arguments.
BRO Keskiverto can u plz solve this problem for me .Cos am new in programming and am trying my best to be better as days goes on..Thanks


write the program with function prototype,calling and definition.Function should return sum and quantity of those array element that are less than X.Function must take argument.EX:Let A(2,3,1,8,3,9,3,6,2,6),X=5..Answer is sum=14,quantity=6..Plz who can help me solve this solution now
Hello jony11,

As keskiverto once said:
Please note that this is not a homework site. We won't do your homework for you. The purpose of homework is that you learn by doing. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.

We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again.

Or say that you do not understand the instructions or how to figure them out.

You can start with this and add to it. Post your work and we can figure it out.

I will work up a program to make sure I have covered everything in the assignment, but it is up to you to make an attempt to do it first. I can help you figure out what is wrong and help you understand why, but yu need to make the attempt first.

Hope that helps,

Andy
Nice talk handy andy..Will start with some online courses and i think that will help me also.thanks for the advice
Hello jony11,

I apologize I was interrupted in my last post and missed adding this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

// <--- Prototypes go here.

int main()
{
	// <--- Your code goes here.


    return 0;
}

// <--- Functions go here.

type FunctionName(Parameter(s))
{
	// <--- Your code here.
}


That should give you a start. Read keskiverto's links and see what you can come up with.

Andy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<iostream>
using namespace std;

void myFunction(int A[], int, int, int &, int &);

int main() {
	int x = 5;
	int A[] = { 2,3,1,8,3,9,3,6,2,6 };

	int sum = 0, quantity = 0;

	myFunction(A, 10, x, sum, quantity);

	cout << "sum = " << sum << endl;
	cout << "quantity = " << quantity << endl;

	

	return 0;
}

void myFunction(int A[], int i, int x, int &sum, int &quantity) {
	for (int j = 0; j < i; j++) {
		if (A[j] < x) {
			sum += A[j];
			quantity++;
		}
	}
}
Topic archived. No new replies allowed.