Im trying to add the elements I entered into an array in increments until the total but I just get the exact same erroneous value when I enter it reaches the function call for the function designed to do it.
#include<iostream>
#include<conio.h>
#include<math.h>
usingnamespace std;
int multiplyarray(int[]);
int main(){
int results[11];
int max=12;
int num[12];
int count=0;
int modarr[11];
int summarray[11];
for(int count=0;count<max;count++)
{
cout<<"Please input a number";
cin>>num[count];
}
cout<< "The series is"<<endl;
for(count=0;count<max;count++)
{
results[count] = num[count];
cout<<results[count]<<" ";
}
cout<<"\nModified array:"<<endl;
for(count=0;count<max;count++){
modarr[count]= multiplyarray(summarray);
cout<<modarr[count]<<" ";
}
getch();
}
int multiplyarray(int num[]){
int sumarray[11];
int countm;
int total=0;
for(countm=0;countm<12;countm++)
{
total=(num[countm]+num[countm+1]);
sumarray[countm]=total;
return sumarray[countm];
}
}
what is you intention on line 38? summarray is uninitialzed. I'd guess that you want to pass num? And yes you will get in modarr[count] always the same value because you do always the same.
In multiplyarray:
sumarray appears useless. Do you want to return total of the array? Why did you name the function multiplyarray? If you want the total do it like so:
1 2 3 4 5 6 7 8 9 10 11 12 13
int multiplyarray(int num[]){
int countm;
int total=0;
for(countm=0;countm<12;countm++)
{
total+=num[countm]; // Note: countm+1 is out of bounds for the last field
}
return total; // Note: return outside the loop
}