| | |
c++ "error C4716: 'F_Ite' : must return a value"
Please support our C++ advertiser: Intel Parallel Studio Home
| View Poll Results: c++ "error C4716: 'F_Ite' : must return a value" I need to return 6 values at a time. | |||
| using dereference | | 0 | 0% |
| cannot be done | | 0 | 0% |
| none of all | | 0 | 0% |
| Multiple Choice Poll. Voters: 0. You may not vote on this poll | |||
Thread Solved |
•
•
Join Date: May 2009
Posts: 32
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
double F_Ite() { //Main Function Start //Locally Data_type Declaration And Initialization : int numElement =20; double *a,*b,*c,*d,*Fc,*Fd; a = new double[numElement]; b = new double[numElement]; c = new double[numElement]; d = new double[numElement]; Fc= new double[numElement]; Fd= new double[numElement]; 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]; std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n"; b[k+1]=d[k]; std::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; std::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]); std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n"; } d[k+1]=c[k]; std::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"; } } //Main Function Close
Hi all,I am a new coder in c++ & have found "error C4716: 'F_Ite' : must return a value".I want to return all the value of a,b,c,Fc,Fd to the main function.But in general return can only return one value.please help me to fulfill this coding.
Thanks
Last edited by Tekmaven; Jun 18th, 2009 at 5:06 pm. Reason: Code Tags
1. About C4716: didn't you know that
2. Use code tag with the language specifier (see this forum announcements):
[code=cplusplus]
source
[/code]
It's impossible to cope with this unformatted nightmare!
3. There are two common ways to "return" several values:
3.1 Declare several function parameters (pointers or references to targets).
3.2 Declare a proper struct or class compound type then fill the object of this type and return it as a function value.
double F_Ite() function must return double type value? And where is return anything-of-double_type in the function body? It's your code, you have wrote double F_Ite() ...2. Use code tag with the language specifier (see this forum announcements):
[code=cplusplus]
source
[/code]
It's impossible to cope with this unformatted nightmare!
3. There are two common ways to "return" several values:
3.1 Declare several function parameters (pointers or references to targets).
3.2 Declare a proper struct or class compound type then fill the object of this type and return it as a function value.
Last edited by ArkM; Jun 16th, 2009 at 5:44 am.
•
•
Join Date: May 2009
Posts: 32
Reputation:
Solved Threads: 0
cpp Syntax (Toggle Plain Text)
#include<iostream> #include<cmath> #include<algorithm> void showdata(void); double R_Fibo(); double F_Ite(); //double 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[]) { std::cout <<"\nThe Function is ' F(x)=e^(-x)+x^2 '"; std::cout <<"\n"; int numElement =20; double *a,*b,*c,*d,*Fc,*Fd,I; a = new double[numElement]; b = new double[numElement]; c = new double[numElement]; d = new double[numElement]; Fc= new double[numElement]; Fd= new double[numElement]; //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"; //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"; //--------------------- //--------------------- double In=b[NI]-a[NI]; std::cout <<"\nThe Interval Reduction At The Final Iteration :" <<"\nI(n)= " << In; std::cout<<"\n"; std::cout << std::endl; system("pause"); //return 0; } void showdata(void) { //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"; std::cout <<"\nBefore The Start Of Interval Reduction"; std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = 0.618056"; std::cout <<"\n"; } double R_Fibo() { //Ratio of two successive terms of Fibonacci Sequence is obtained using Binet's Formula //Function (F(m-1)/Fm) Defination : 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; } double F_Ite() { //F_Ite Function Start //Locally Data_type Declaration And Initialization : int numElement =20; double *a,*b,*c,*d,*Fc,*Fd; a = new double[numElement]; b = new double[numElement]; c = new double[numElement]; d = new double[numElement]; Fc= new double[numElement]; Fd= new double[numElement]; for(int k=1;k<(NI-1);k++) { //Main 'for' Loop under F_Ite() 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]; std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n"; b[k+1]=d[k]; std::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; std::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]); std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n"; } d[k+1]=c[k]; std::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
this is my total program.so how to return several values.
Last edited by Tekmaven; Jun 18th, 2009 at 5:10 pm. Reason: Code Tags
As the other guys have suggested, there are several ways around the problem.
The error you're getting is because your F_Ite() function does not return a value.
A function can only return one value, the only way of returning several values would be to either create all of the variables you want returned outside of your function and pass them into your function as pointers or references, or pass them as an array of pointers.
You could then change the return type of the function to void as the function will manipulate the contents of the pointers, so it won't need to return anything.
Or you could get your function to return an array of pointers.
I'm not sure how au-fait you are with the idea of pointers and arrays, so for now I'll go with the idea of creating the values outside of the function and passing them individually as pointers.
Here's what the code would look like:
NOTE: The bulk of the above is your code, just rejigged a little.
DISCLAIMER: I haven't compiled or tested this, but it should be more or less correct!
Cheers for now,
Jas.
The error you're getting is because your F_Ite() function does not return a value.
A function can only return one value, the only way of returning several values would be to either create all of the variables you want returned outside of your function and pass them into your function as pointers or references, or pass them as an array of pointers.
You could then change the return type of the function to void as the function will manipulate the contents of the pointers, so it won't need to return anything.
Or you could get your function to return an array of pointers.
I'm not sure how au-fait you are with the idea of pointers and arrays, so for now I'll go with the idea of creating the values outside of the function and passing them individually as pointers.
Here's what the code would look like:
CPP Syntax (Toggle Plain Text)
#include<iostream> #include<cmath> // pass values into your function void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd) { //Main Function Start // you could initialise your variables here, or outside of the function. // I've gone for the latter, but whatever floats your boat! 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]; std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n"; b[k+1]=d[k]; std::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; std::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]); std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n"; } d[k+1]=c[k]; std::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"; } } //Main Function Close int main() { // declare your pointers outside of your function and pass them as parameters to F_Ite double *a,*b,*c,*d,*Fc,*Fd; // you could optionally initialise them before passing them to your function int numElement =20; a = new double[numElement]; b = new double[numElement]; c = new double[numElement]; d = new double[numElement]; Fc= new double[numElement]; Fd= new double[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! return 0; }
DISCLAIMER: I haven't compiled or tested this, but it should be more or less correct!
Cheers for now,
Jas.
Last edited by JasonHippy; Jun 16th, 2009 at 6:33 am.
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Those who understand binary .....
And those who don't!
•
•
Join Date: May 2009
Posts: 32
Reputation:
Solved Threads: 0
•
•
•
•
1. About C4716: didn't you know thatdouble F_Ite()function must return double type value? And where isreturn anything-of-double_typein the function body? It's your code, you have wrotedouble F_Ite()...
2. Use code tag with the language specifier (see this forum announcements):
[code=cplusplus]
source
[/code]
It's impossible to cope with this unformatted nightmare!
3. There are two common ways to "return" several values:
3.1 Declare several function parameters (pointers or references to targets).
3.2 Declare a proper struct or class compound type then fill the object of this type and return it as a function value.
Declare several function parameters (pointers or references to targets). I have tried this but unable to get success.I have post my total code just pls check it out & pls suggest me some useful concept.
Firstly Please USE Code tags, as it is very hard to understand the post that you have posted.
I personally feel that for you the best way to return your doubles is with a struct.
for example
then now f1.a and f1.b will point to the doubles.
THough remember that pointers to local variables is undefined and only the variables initialised with new are returned back.
DO not forget to use the
I personally feel that for you the best way to return your doubles is with a struct.
for example
c++ Syntax (Toggle Plain Text)
struct Values{ //Creates a new datatype named values double* a, *b;//SO on. } Values func1()// function named func1 returning type Values { double *s, *z; /*Do something with s and z*/ Values a1;// Now we made a variable named a1 of type value a1.a=&s; //We know that Values have a member a; a1.b=&z; //And also b, We now make them point to the local doubles return a1; //Return type of values } int main() Values f1=func1(); }
THough remember that pointers to local variables is undefined and only the variables initialised with new are returned back.
DO not forget to use the
delete [] later. •
•
•
•
I personally feel that for you the best way to return your doubles is with a struct.
That would be preferable to the method I put forward.
I just wasn't sure how familiar the OP was with structs, pointers and arrays. So I went with the simplest example passing each value separately....
Although looking my post now, why I posted the entire body of the function instead of just posting a more compact example is beyond me! heh heh

Good solution Sky!
There are 10 types of people in this world.....
Those who understand binary .....
And those who don't!
Those who understand binary .....
And those who don't!
•
•
Join Date: May 2009
Posts: 32
Reputation:
Solved Threads: 0
hi friends,right now I am facing this type of problem.Will anyone please help me out.please as I am New inC++ & after tried not getting.
Thanks
Thanks
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<cmath> #include<algorithm> using namespace 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 = new double[numElement]; b = new double[numElement]; c = new double[numElement]; d = new double[numElement]; Fc= new double[numElement]; Fd= new double[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
![]() |
Similar Threads
- Error: "There was an error generating the XML document" (RSS, Web Services and SOAP)
- Error 'not all code paths return a value' (C#)
- PLEASE HELP "Error loading operating system" (Windows NT / 2000 / XP)
- "error has occured in script on this page" (Windows NT / 2000 / XP)
- "Error msg.when trying to open IE6" (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: Using Libcurl: how to 'install' it?
- Next Thread: I need some help...
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






