Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double' (http://www.go4expert.com/forums/error-c2664-fite-convert-parameter-1-t18125/)

sdmahapatra 20Jun2009 13:55

error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double'
 
Hi all C++ experts,I am new in C++ & got an
error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double' . please anyone help me out fron this problem & please tell me something about this whitch help me in future.
Thanks

Code:


#include
<iostream>
#include<cmath>
#include<algorithm>
usingnamespace std; // you should not use this statement.
void F_Ite(double,double,double,double,double,double);
// never ever declare global data in C++
//Globally Data_type Declaration & Initialization :
double z=0.0001;
double NR=0.01;
int NI=11;
double RF;
int main(int argc, char* argv[]) // put the othe arguments for main (int argc, char* argv[])
{
//Result Of A Fibonacci_Search Algorithm Operation On A Given Function :
std::cout <<"\nThe Function is ' F(x)=e^(-x)+x^2 '";
std::cout <<
"\n";

// declare your pointers outside of your function and pass them as parameters to F_Ite
double *a,*b,*c,*d,*Fc,*Fd,I;
// you could optionally initialise them before passing them to your function
int numElement =20;
a =
newdouble[numElement];
b =
newdouble[numElement];
c =
newdouble[numElement];
d =
newdouble[numElement];
Fc=
newdouble[numElement];
Fd=
newdouble[numElement];

// now call the function
F_Ite(a,b,c,d,Fc,Fd);
// Now you can cout your values, or do whatever with them
// don't forget to delete them when you're done.
// wherever you create something with 'new' you should
// always call 'delete' when finished!

//User Specify The Interval :
std::cout << "\nGive The Initian Point :" <<"\na1 =";
std::cin >> a[1];
std::cout <<
"\nGive The Final Point :" <<"\nb1 =";
std::cin >> b[1];


//Find Distance Between The Starting Interval :
I=(b[1]-a[1]);
std::cout <<
"\nInterval Reduction At The Initial Iteration :"<< "\nI(1) = " << I <<"\n";

//For Accuracy Exactness Need A Small Pertubation At The Final Interval
std::cout <<"\nFor Accuracy At The Final Interval, Taken The Small Perturbation z :";
std::cout <<
"\nTaken z = 0.0001" << "\n";

//Give The Prescribe Interval Reduction :
std::cout <<"\nNeeded The Prescribe Interval Reduction :" <<"\nNR = 0.01 units";
std::cout <<
"\n";

//Calculate The Number Of Iteration From The Given Interval Reduction :
//By Fibonacci Series
std::cout <<"\nAccording To The Interval Reduction";
std::cout <<
"\nThe Requring Number Of Iteration :" << "\nNI = 11 times";
std::cout <<
"\n";
std::cout <<
"\n";

system(
"pause"); // this is a platform specific call. do not use this.


//To Calculate The Ratio of two consecutive Fibo_Num (F(m-1)/Fm) :
//Function (F(m-1)/Fm) Declaration :
double R_Fibo();
std::cout <<
"\nBefore The Start Of Interval Reduction";
std::cout <<
"\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = 0.618056";
std::cout <<
"\n";

//Here The Beginnins Of Iteration Technique

//We Introduce Two Another Points For Getting Two New Interval Of Uncertainty
//First Point 'c1' And Second Point 'd1' :
c[1]=b[1]-(R_Fibo()*I);
std::cout <<
"\nPlaced A Point c1 Within The Initial Interval :"<< c[1];
d[1]=a[1]+(R_Fibo()*I);
std::cout <<
"\nPlaced Another Point d1 Within The Initial Interval :"<<d[1];
std::cout <<
"\n";
std::cout <<
"\n";

//Showing The Starting Reduction :
//----------------
//----------------
std::cout <<"At The First Iteration :\n";
std::cout <<
"The Value Of a1=" << a[1] << "\n";
std::cout <<
"The Value Of b1=" << b[1] << "\n";
std::cout <<
"The Value Of c1=" << c[1] << "\n";
std::cout <<
"The Value Of d1=" << d[1] ;
//Function 'Fc1' at point 'c1' And Function 'Fd1' at point 'd1':
//--------------------

// write a function which takes one argument and returns the value. use it here instead of explicit coding.
Fc[1]=(exp(-c[1]))+(c[1]*c[1]);
std::cout <<
"\nAt c1 The Function Value Fc1=" << Fc[1];
//std::cout <<"\n";
Fd[1]=(exp(-d[1]))+(d[1]*d[1]);
std::cout <<
"\nAt d1 The Function Value Fd1=" << Fd[1];
std::cout <<
"\n";
std::cout <<
"\n";
//---------------------
//---------------------
//system("pause");
// this must be defined outside of main and called here explicitly.





double In=b[NI]-a[NI];
std::cout <<
"\nThe Interval Reduction At The Final Iteration :" <<"\nI(n)= " << In;
std::cout<<
"\n";

delete [] a;
delete [] b;
delete [] c;
delete [] d;
delete [] Fc;
delete [] Fd;

std::cout << std::endl;
system(
"pause");
//return 0;
}


//Ratio of two successive terms of Fibonacci Sequence is obtained using Binet's Formula
//Function (F(m-1)/Fm) Defination :
double R_Fibo()
{
double n1=1-(sqrt((double)5));
double n2=1+(sqrt((double)5));
double s=(n1/n2);
//cout << "\nsThe Value Of s = " << s <<"\n";
double s1=(sqrt((double)5)-1)/2;
//cout << "\nThe Value Of s1 = " << s1 <<"\n";
double RF=s1*((1-pow(s,NI))/(1-pow(s,(NI+1))));

//std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = " << RF <<"\n";
//std::cout << RF;
return RF;
}

// pass values into F_Ite() function
void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd)
{
//F_Ite Function Start

for(int k=1;k<(NI-1);k++)
{
//Main 'for' Loop Start
std::cout <<"\n";
system(
"pause");
std::cout <<
"\n";
std::cout <<
"At The "<<k+1<<" Iteration :\n";

if(Fc[k]<Fd[k])
{
//Outer 'if' Start
a[k+1]=a[k];
cout <<
"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
b[k+1]=d[k];
cout <<
"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
//c[k+1]=b[k+1]-(0.618034*((1-pow(-0.381966,NI-k))/(1-pow(-0.381966,NI-k+1))))*(b[k+1]-a[k+1]);
//cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
if(k==(NI-1))
{
c[k+1]=c[k+1]+z;
cout <<
"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
}
else
{
c[k+1]=b[k+1]-(0.618034*((1-pow(-0.381966,NI-k))/(1-pow(-0.381966,NI-k+1))))*(b[k+1]-a[k+1]);
cout <<
"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
}
d[k+1]=c[k];
cout <<
"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
Fc[k+1]=(exp(-c[k+1]))+(c[k+1]*c[k+1]);
std::cout <<
"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
//std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k] << "\n";
Fd[k+1]=Fc[k];
//std::cout <<"The Value Of Fd" << k+1 << "=" << Fc[k] << "\n";
std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";

}
//Outer 'if' Close
else
{ //Outer 'else' Start
a[k+1]=c[k];
std::cout <<
"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
b[k+1]=b[k];
std::cout <<
"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
c[k+1]=d[k];
std::cout <<
"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
//d[k+1]=a[k+1]+((0.618034)*((1-pow((-0.381966),(NI-k)))/(1-pow((-0.381966),(NI-k+1)))))*(b[k+1]-a[k+1]);
//std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";

if(k==(NI-1))
{
d[k+1]=d[k+1]+z;
std::cout <<
"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
}
else
{
d[k+1]=a[k+1]+((0.618034)*((1-pow((-0.381966),(NI-k)))/(1-pow((-0.381966),(NI-k+1)))))*(b[k+1]-a[k+1]);
std::cout <<
"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
}

Fc[k+1]=Fd[k];
//std::cout <<"The Value Of Fc" << k+1 << "=" << Fd[k] << "\n";
std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
Fd[k+1]=(exp(-d[k+1]))+(d[k+1]*d[k+1]);
std::cout <<
"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
//std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k] << "\n";
} //Outer 'else' Close
} //Main 'for' Loop Close
//Another 'if' Condition Start But Within The 'for' Loop
if(Fc[10]<Fd[10])
{
std::cout <<
"\n";
std::cout <<
"\nAt Final Iteration :\n";
a[NI]=a[NI-1];
b[NI]=d[NI-1];
std::cout <<
"The Value Of a11 =" << a[NI] << "\n";
std::cout <<
"The Value Of b11 =" << b[NI] << "\n";
}
else
{
a[NI]=c[NI-1];
b[NI]=b[NI-1];
std::cout <<
"The Value Of a11 =" << a[NI] << "\n";
std::cout <<
"The Value Of b11 =" << b[NI] << "\n";
}
}
//F_Ite Function Close


xpi0t0s 21Jun2009 05:12

Re: error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double'
 
The error is actually quite clear. F_Ite takes doubles (according to the function prototype), and you're passing in double arrays.

Also your prototype doesn't match the function itself. Here's your prototype:
Code:

void F_Ite(double,double,double,double,double,double);
and here's the function itself:
Code:

void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd)
So I think your prototype is wrong.

Also there is an error on this line:
Code:

using namespace std; // you should not use this statement.
There's nothing wrong with "using" statements; this means you don't have to clutter your code with loads of "std::" all over the place.

Also bollocks, although it's amusing that you have global data declared immediately after this false statement:
Code:

// never ever declare global data in C++
It's true that you should try to avoid global data wherever possible because of the dependencies it creates, but if you truly have data that is used all over the program then it doesn't make any sense to hide it in a function and to have to keep passing pointers to it all over the place.

I agree with the comment, but why then is it in the code?
Code:

system("pause"); // this is a platform specific call. do not use this.
Why is this correct statement commented out (although it should return EXIT_SUCCESS, not zero):
Code:

//return 0;
Unnecessary comment. The point of comments is to explain the thinking behind the code, not to extend the syntax with unnecessary statements of the obvious. It's obvious that this is the F_Ite function start; you don't need a comment that says it is:
Code:

void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd)
{ //F_Ite Function Start

Same again. However I'm getting the feeling that this is code aimed at absolute beginners so if that's the case then the overcommenting is probably a learning tool. But please drop this as soon as possible and use comments to EXPLAIN the code, not just to RESTATE the code in other words:
Code:

for(int k=1;k<(NI-1);k++)
{ //Main 'for' Loop Start


xpi0t0s 21Jun2009 05:17

Re: error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double'
 
So when faced with an error you don't understand, think about the LITERAL meaning of EXACTLY what it says. Usually you'll find that most errors are written in pretty plain language. They mean you've done something wrong, so you have to accept that and work out what it is that you've done wrong. Often failure to understand errors comes from the (wrong) conviction that you've done nothing wrong and the compiler doesn't know what it's talking about, and that is not a useful starting point.

sdmahapatra 21Jun2009 13:18

Re: error C2664: 'F_Ite' : cannot convert parameter 1 from 'double *' to 'double'
 
Quote:

Originally Posted by xpi0t0s (Post 50196)
So when faced with an error you don't understand, think about the LITERAL meaning of EXACTLY what it says. Usually you'll find that most errors are written in pretty plain language. They mean you've done something wrong, so you have to accept that and work out what it is that you've done wrong. Often failure to understand errors comes from the (wrong) conviction that you've done nothing wrong and the compiler doesn't know what it's talking about, and that is not a useful starting point.

yes I will follow your suggestion and thank you for your kind touch.


All times are GMT +5.5. The time now is 20:50.