#include <iostream>
usingnamespace std;
int blue(int array[], int num);
int main (){
int red [3]={2,9,8};
cout << "the sum of the numbers in the array is: " << blue(red,3) << endl;
system("pause");
return 0;
}
int blue(int array[], int num){
int sum=0;
for(int x=0;x<num;x++){
sum+=array[x];
}
return sum;
}
then i wanted to make one with decimals so i used float but i can't manage to make it work
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
float blue(float array[],int num);
int main (){
float red [3]={2.5,9.6,8.7};
cout << "the sum of the numbers in the array is: " << blue(red,3) << endl;
system("pause");
return 0;
}
float blue(float array[],int num){
float sum=0;
for(float x=0;x<num;x++){
sum+=array[x];
}
return sum;
}