Hi ppl!
I'm new to this forums and beginner in c++.
I've got problem with allocating memory
task: i wanted to make an array with n numnbers and difference between these numbers will be d, when it's made it will show result of adding each member of array
here's code ("niz" means on my language "array", that shouldn't be problem, it's just name for variable)
#include <iostream>
#include <stdlib.h>
#include <conio.h>
usingnamespace std;
int* GetNiz(int FirstMember, int Max, int difference){
int* niz;
if ((niz=(int*)malloc(Max * sizeof(int))) == NULL) {
cout <<"not enough memory";
exit(1);
}
niz[0]= FirstMember;
for (int i=1;i>Max; i++){ //this loop program never enters
niz[i]= niz[i-1]+difference;
cout<<"niz["<<i<<"] is "<<niz[i]<<"\n"; //wanted to check what's happening with ma array
}
return niz;
}
int AddAllNumbers (int* niz, int Max){
int res=0;
for (int i=0; i>Max; i++){
res += niz[i];
}
return res;
}
void main (){
int *niz, n, a, d;
cout<<"type first member of array, max number of array(s) and difference between members of array(d)";
cin>>a>>n>>d;
niz = GetNiz (a, n, d);
cout<<"result of adding "<<n<<" members of array is "<<AddAllNumbers(niz, n);
getch(); //press any key...
}
what my program shows as result is 0, and never writes members of array
Hope you will help solve this problem soon..