array function, sum

Write your question here.

good day, im having difficulty understanding the problem "cannot convert double to int for argument". sometimes when i change something and runs, it give a sum of 1. im new and and help would be appreciated.

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  #include<iostream>

using namespace std;

void menu();
int add(int a[],int size);

int main()
{
	int operation;
	double num[4];
	
	menu();
	cout<<"Choose Operations: ";
	cin>>operation;
	
	if(operation==1){
		for(int x=0;x<4;x++){
			cout<<"Enter Value " <<x+1 <<": ";
			cin>>num[x];
			add(num,x);
		}
		cout<<"the Sum is: " <<add <<endl;
	}	
	
}

void menu(){
	
	cout<<"Operations" <<endl;
	cout<<"1 add" <<endl;
	cout<<"2 subraction" <<endl;
	cout<<"3 Multiplications" <<endl;
}

int add(int a[],int size){
	int sum=0;
	for(int x=0;x<size;x++)
	{
		sum=sum+a[x];
	}
	return sum;
	
}
closed account (SECMoG1T)
your error is on line 11
1
2
3
///double num[4]; this
///should be
 int num[4];
or double add(double a[],int size)
thank you for your reply. it runs but why im getting the answer 1 in my sum? thanks again
closed account (SECMoG1T)
hello you aren't adding the values,

1
2
3
4
5
6
7
8
9
10
11
12
if(operation==1){
                int total =0;///create a variable
                int size = 4;

		for(int x=0;x<size;x++){
			cout<<"Enter Value " <<x+1 <<": ";
			cin>>num[x];
			///add(num,x); call the function outside the loop
		}
                total = add(num,size);
		cout<<"the Sum is: " <<total<<endl;
	}
thank you all for the replies. god bless you all.
Topic archived. No new replies allowed.