Hello,
the following code doesnot return the corect values to the main function. However it prints the correct values within the function. Also the same when written in C works absolutely fine. Pls tell me where im going wrong and correct me. U can run it and check!
Thanks
Prads
[code=cpp]
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
float *calcloopcoef(f loat lbw,float zeta,float k);
int main()
{
float *arrt;
arrt=calcloopco ef(25,0.7,.25);
cout<<"The returned values are"<<endl<<arr t[0]<<endl<<arrt[1]<<endl;
getchar();
return 0;
}
float *calcloopcoef(f loat lbw,float zeta,float k)
{
float arrtau[2],wn;
wn=lbw*8*zeta/(4*pow(zeta,2)+ 1);
arrtau[0]=k/pow(wn,2);
arrtau[1]=(2*zeta)/wn;
cout<<"values within fn"<<endl<<arrt au[0]<<endl<<arrta u[1]<<endl;
return arrtau;
}[/code]
the following code doesnot return the corect values to the main function. However it prints the correct values within the function. Also the same when written in C works absolutely fine. Pls tell me where im going wrong and correct me. U can run it and check!
Thanks
Prads
[code=cpp]
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
float *calcloopcoef(f loat lbw,float zeta,float k);
int main()
{
float *arrt;
arrt=calcloopco ef(25,0.7,.25);
cout<<"The returned values are"<<endl<<arr t[0]<<endl<<arrt[1]<<endl;
getchar();
return 0;
}
float *calcloopcoef(f loat lbw,float zeta,float k)
{
float arrtau[2],wn;
wn=lbw*8*zeta/(4*pow(zeta,2)+ 1);
arrtau[0]=k/pow(wn,2);
arrtau[1]=(2*zeta)/wn;
cout<<"values within fn"<<endl<<arrt au[0]<<endl<<arrta u[1]<<endl;
return arrtau;
}[/code]
Comment