I have a problem in C++(complier dev 4.9.9.2). My program have complie with no error but out put is wrong and not run show with massage “ some intermediated data is missing”. In debugging its show massage “segmentation Error” .
#include<iostream>
#include<math.h>
#include<conio.h>
#include<fstream>
#include<dos.h>
#include<iomanip>
const int row=195;
const int col=235;
using namespace std;
float velocity (int,float,float,float,float);
int main()
{
ifstream in("data.txt");
ofstream out("vel.txt");
int **EL= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **el= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **SA= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **RL= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **LSD= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **ASP= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **SL= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **X= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
int **Y= (int**)malloc(row*col*sizeof(int) + col*sizeof(int*));
float **FC= (float**)malloc(row*col*sizeof(float) + col*sizeof(float*));
double **vel_g=(double**)malloc(row*col*sizeof(double) + col*sizeof(double*));
int i,m,n ,j,x,y,t,Max,k,k1;
float cvel,vel1,vel2,vel3,vel4,vel5,vel6,vel8,vel7,vel;
for(i=0;i<row;i++)
for( j=0; j<col;j++)
{
in>>el[i][j];
EL[i][j]=el[i][j];
in>>RL[i][j];
in>>SA[i][j];
in>>SL[i][j];
in>>FC[i][j];
in>>LSD[i][j];
in>>ASP[i][j];
}
for( k=0; k<row ;k++)
for( k1=0; k1<col;k1++)
{
Max=-2;
for(int i=0; i<row;i++)
for(int j=0; j<col;j++)
if(el[i][j]>Max)
{
Max=el[i][j];
x=j;
y=i;
}
X[k][k1]=x;
Y[k][k1]=y;
el[y][x]=-21;
cout<<k<<"\t"<<k1<<"\t"<<X[k][k1]<<endl;
}
for(int a=0;a<row;a++)
for(int b=0;b<col;b++)
vel_g[a][b]= 0 ;
for(int k=0; k<row;k++)
for(int k1=0;k1<col;k1++)
{
n=X[k][k1];
m=Y[k][k1];
if(1==LSD[m][n])
{
while(SA[m][n]>=25)
{
vel = velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
t=ASP[m][n];
switch(t)
{
case(1): {m= m-1;n=n; vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error1\n";} break;}
case(2): {m= m-1;n=n+1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error2\n"; }break;}
case(3): {m= m;n=n+1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error3\n"; }break;}
case(4): {m= m+1;n=n+1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error4\n"; }break;}
case(5): {m= m+1;n=n;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error5\n"; }break;}
case(6): {m= m+1;n=n-1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error6\n"; }break;}
case(7): {m= m;n=n-1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error7\n"; }break;}
case(8): {m= m+1;n=n-1;vel=velocity(RL[m][n],FC[m][n],SL[m][n],SA[m][n],vel_g[m][n]);
vel_g[m][n]= sqrt((vel_g[m][n]*vel_g[m][n])+(vel*vel)+(2*vel_g[m][n]*vel*cos(45*(22/7))));
if(m<0||m>row||n<0||n>col) {cout<<"error8\n"; }break;}
}
} }
}
for(int c=0;c<row ;c++)
for(int d=0;d<col;d++)
{ out<<c<<"\t"<<d<<"\t";
out<<vel_g[c][d]<<'\n';
}
return 0;}
float velocity( int RL,float fric,float slope, float slopeangle, float ve)
{
int heg;
float D,b;
heg=RL;
b=fric;
if(ve>1000)
{
cout<<"\t"<<"heg="<<heg<<"\tb="<<b<<"\tve"<<ve<<"\t";
getch();
}
const double g =9.781;
slopeangle=((slopeangle*(22/7))/180);
float x = (2*g*(heg-(b*slope*cos(slopeangle))));
if(x<0) x=0;
D=slope*cos(slopeangle);
float y = sqrt(x+(ve*ve));
if(y>100000)
{
cout<<"\td="<<D<<"\tfc="<<b<<"\tg="<<g<<"\theg="<<heg<<"\nve="<<ve<<"\ty="<<y<<"\n";
}
return y;
}