problem with allocating memory

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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <stdlib.h>
#include <conio.h>
	
	using namespace 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..

cheers

Silvestar
Last edited on
Line 14 has an incorrect exit condition.
thanks!
i already thought that i don't know how to allocate memory :P
Topic archived. No new replies allowed.