function

how to solve this program problem, to get the output of total integers and smallest number...

#include<iostream.h>
int sum(int x);
int smallest(int y);

void main()
{
int number[5],x,y;

cout<<"Key in 5 integers : "<<endl;

for (x=0;x<5;x++) {
cin>>number[x];

}

}
int sum(int num[5]) {
int x=0, total=0;
for (x=0;x<5;x++) {
total=total+num[x];

cout<<"\nTotal of 5 integers = "<<total;
}
return total;

}

int smallest(int num[5]) {
int y=0, min=0;
for(y=0;y<5;y++) {
if (num[y]<min)
min=num[y];

cout<<"\nSmallest number = "<<min;

}
return min;
}
You have to call the functions in the main()

http://www.cplusplus.com/doc/tutorial/functions/
Last edited on
just call these function from main and pass them array.
as you are going to pass an array to both functions ,prototypes should be like this : int sum(int x[]);
int smallest(int y[]);
and you are displaying total and smallest number in functions so there is no need to return value so better use void.
do not cout total and smallest in body of for loop because in for loop you are doing processing for your results. result will be attained when loop will end.
Topic archived. No new replies allowed.