need your help

hello, i have question , i have an array a[4];
and i did the function belw first one to ask the user to put the elemints then find the sum ,my question is i want to send the alemints that the user put it to the malti funtion without repeat read funtion in malti funtion , how i do it ??, please answer me i have exam.
thank you so much

1
2
3
4
5
6
7
8
9
10
11
12
13
  float read(int a[4]){
	int sum=0;
cout<<"enter please an array 4\n";
for(int i=0;i<4;i++){
	cin>>a[4];
	sum=sum+a[4];
}
return sum;
}
float malti(int a[4]){

return
}
i have exam


Are you having an exam right now? Then nobody should help you cheating!
it is not right now but tomorow and this an example to help me to understand what i should do for tomorow , you miss understand me and i know my english is not perfect sorry
Ok, there are some mistakes:

sum=sum+a[4]; is wrong: you are adding the fifth value of the array every time (also when it has not been read yet). You should do sum=sum+a[i];

Then you should not repeat the read function. Instead you should have a read function that fills your array, then pass your array to other functions that process its values and do the calculations you want.
oh thank you i did not noticed this mistake , yes how can i pass the array after the user put it to other function ? for example i did the sum and i return a[i];
then how can i send the a[i];it to malti funtion in this example ?
can you write please how it will be ?

thank you so much.
closed account (SECMoG1T)
These too is an error cin>>a[4]; adopt @minomic strategy.

About calling your functions and passing your array these should give you an idea.
1
2
3
4
5
6
7
8
9
10
11
/// functions defined here
 int main ()
{
    int array [4];
    float sum=0.0, result=0.0;

    sum=read (array);
    result=malti (array);
   /// use results

 }
acctlully i understand ,but how i do it inside the function but not in funtion call.
here is another example ,
i have array a[10], and in the first funtion i have to ask the user to input 10 number , and i have to send it to the scound funtion and categorize them itno even and odd , then i have to send it to print funtion to print it on screen . this is my tried but i know it wrong becuse i dont know how to send the array to other funtion , if you can please help me to understand how . thank you



#include<iostream>
using namespace std;
void read(int[]);
void spolit(int []);
void print(int []);

int main(){
int a[10];
read(a);
print(a);
system("pause");
return 0;
}
void read(int a[10]){
cout<<"enter pleae the elements \n";
for(int i=0;i<10;i++)
cin>>a[i];
}
void spolit(int a[10]){
int even=0;
int odd=0;
for(int i=0;i<10;i++){
if(a[i]%2==0)
even=even+a[i];
else
odd=odd+a[i];
}
}
void print(int a[10])
{
spolit(a);
}
Ok, first of all what exactly is your spolit function doing? It calculates the sum of the even and the odd elements, then... what? The variables "even" and "odd" only live inside that function: they are never returned to other parts of the code and are completely useless.

Then why do you call spolit inside your print function? This should only print the elements of the array... nothing more than this.
Topic archived. No new replies allowed.