Hi there, first time posting and asking about c++ in this forum. I hope you can explain to me what I did wrong in my code.
My professor asked me to build a program with recursive functions and the programs must return the average of the sum of the all of the vectors elements which are numbers.
Here's my code
#include <iostream>
using namespace std;
int getSuma(int v[], int currentPos, int suma)
int main ()
{
int v[] = {10,4,5,2,8,1};
int x;
for(x = 0; x <6 ; x++){
cout << v[x]<< endl;
}
cout << "The average of the sum is"<< getSuma(v, v[0], 0) << endl;
system(" pause" );
}
int getSuma(int v[], int currentPos, int suma)
{
int x;
for( x = 0; x < 6; x++)
{
if (currentPos <6) {
suma = 0;
suma+= v[currentPos];
}
else
return suma;
}
}
What I did wrong? My code dont debug. Any help or solution will be enormously thanked. :)
So far I've done this...but still I dont know what Im doing wrong.
Can anyone please tell me?
#include <iostream>
using namespace std;
int getsuma(int v[], int currentPos);
void main ()
{
int v[] = {10,4,5,2,8,1};
int x;
for(x = 0; x <6 ; x++){
cout << v[x]<< endl;
// getsuma(0, v[0]);
}
cout << "The average of the sum is"<< getsuma(0, v[0])<< endl;
system(" pause" );
}
int getsuma(int v[], int currentPos){
if (currentPos <6) {
int suma;
suma= suma +v[currentPos];
suma = suma/6;
}
return (suma);
Hi! I'm still working in the code I made this. So far I can get the average of the add (sum) but its suppose to give me back the number 5 but gives me a decimal number.
Please help.
#include <iostream>
using namespace std;
double getsuma(int v[], int currentPos, double suma);
int main ()
{
int v[] = {10,4,5,2,8,1};
int x=0;
for(x = 0; x <6 ; x++)
{
cout<< v[x] <<endl;
}
cout << " Promedio: " << getsuma(v, 0, 0) <<endl;
system ("Pause");
}
double getsuma(int v[], int currentPos, double suma){