+ 1

can you help me please? Why doesn't this code work?

#include <iostream> using namespace std; int** constructor(int n,int m){ int*z=new int *[m]; for (int i=0;i<m;i++) z[i]=new int[n]; for (int i=0;i<m;i++) { for(int j=0;j<n;j++) z[i][j]=i+3*j; } return z; } int calculator(int**key,int m,int n){ int count=1; for (int i=0;i<m;i++){ for(int j=0;j<n;j++){ if(key[i][j]!=0) {count=count*key[i][j]; } } } return count; } void show(int** key,int m,int n){ for(int i=0;i<m;i++){ cout<<endl; for(int j=0;j<n;j++) cout<<"\t"<<key[i][j]; } } void calcshow(int m){ cout<<endl<<"\n"<<"\t"<<m<<"\n"<<"\n"; } int main() { int m=5; int n=6; int** z=constructor(m,n); int b=calculator(z,m,n); show(z,m,n); calcshow(b); return 0; }

22nd Jan 2017, 6:46 PM
Armen Armenakyan
Armen Armenakyan - avatar
2 Respostas
+ 2
change line 5 to: int**z=new int *[m];
22nd Jan 2017, 7:21 PM
ymoon
+ 1
What is the expected action?
22nd Jan 2017, 7:10 PM
Sam