So I'm doing a code which sums up all elements of field but I have to use pointers :( No matter what I tried I get 1 as output. Tried same code with multiplication but still nothing... Code:
#include <iostream>
#include <cmath>
using namespace std;
float vrat=0;
int suma (int pok2, int vel22){
for(int z=0; z<vel22; z++){
vrat+=pok2;
}
return vrat;
}
int main()
{
/// 2. zadatak
int vel2;
int *vel22=&vel2;
cout<<"Unesi broj elemenata koje hoces upisati"<<endl;
cin>>vel2;
int polje2[vel2];
cout<<"Kreni unosit elemente "<<endl;
for(int z=0; z<vel2; z++){
cin>>polje2[z];
}
int *pok2=&polje2[vel2];
suma(*pok2, *vel22);
cout<<"Suma elemenata je "<<suma<<endl;
return 0;
}
Thank you!