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: sdmahapatra is an unknown quantity at this point 
Solved Threads: 0
sdmahapatra sdmahapatra is offline Offline
Light Poster

c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #1
Jun 16th, 2009
  1. double F_Ite()
  2. { //Main Function Start
  3. //Locally Data_type Declaration And Initialization :
  4. int numElement =20;
  5. double *a,*b,*c,*d,*Fc,*Fd;
  6. a = new double[numElement];
  7. b = new double[numElement];
  8. c = new double[numElement];
  9. d = new double[numElement];
  10. Fc= new double[numElement];
  11. Fd= new double[numElement];
  12.  
  13.  
  14. for(int k=1;k<(NI-1);k++)
  15. { //Main 'for' Loop Start
  16. std::cout <<"\n";
  17. system("pause");
  18. std::cout <<"\n";
  19. std::cout <<"At The "<<k+1<<" Iteration :\n";
  20.  
  21. if(Fc[k]<Fd[k])
  22. { //Outer 'if' Start
  23. a[k+1]=a[k];
  24. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  25. b[k+1]=d[k];
  26. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  27. //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]);
  28. //cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  29. if(k==(NI-1))
  30. {
  31. c[k+1]=c[k+1]+z;
  32. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  33. }
  34. else
  35. {
  36. 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]);
  37. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  38. }
  39. d[k+1]=c[k];
  40. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  41.  
  42. Fc[k+1]=(exp(-c[k+1]))+(c[k+1]*c[k+1]);
  43. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  44. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k] << "\n";
  45.  
  46. Fd[k+1]=Fc[k];
  47. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fc[k] << "\n";
  48. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  49.  
  50.  
  51. } //Outer 'if' Close
  52. else
  53. { //Outer 'else' Start
  54. a[k+1]=c[k];
  55. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  56. b[k+1]=b[k];
  57. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  58. c[k+1]=d[k];
  59. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  60. //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]);
  61. //std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  62.  
  63. if(k==(NI-1))
  64. {
  65. d[k+1]=d[k+1]+z;
  66. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  67. }
  68.  
  69. else
  70. {
  71. 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]);
  72. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  73. }
  74.  
  75.  
  76. Fc[k+1]=Fd[k];
  77. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fd[k] << "\n";
  78. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  79. Fd[k+1]=(exp(-d[k+1]))+(d[k+1]*d[k+1]);
  80. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  81. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k] << "\n";
  82.  
  83. } //Outer 'else' Close
  84. } //Main 'for' Loop Close
  85.  
  86. //Another 'if' Condition Start But Within The 'for' Loop
  87. if(Fc[10]<Fd[10])
  88. {
  89. std::cout <<"\n";
  90. std::cout <<"\nAt Final Iteration :\n";
  91. a[NI]=a[NI-1];
  92. b[NI]=d[NI-1];
  93. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  94. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  95. }
  96. else
  97. {
  98. a[NI]=c[NI-1];
  99. b[NI]=b[NI-1];
  100. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  101. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  102. }
  103.  
  104. } //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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
1
  #2
Jun 16th, 2009
1. About C4716: didn't you know that 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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #3
Jun 16th, 2009
Why dont you use an array of pointers and return the array of pointers.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 32
Reputation: sdmahapatra is an unknown quantity at this point 
Solved Threads: 0
sdmahapatra sdmahapatra is offline Offline
Light Poster

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #4
Jun 16th, 2009
  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4.  
  5.  
  6. void showdata(void);
  7. double R_Fibo();
  8. double F_Ite();
  9. //double F_Ite(double,double,double,double,double,double);
  10. // never ever declare global data in C++
  11.  
  12. //Globally Data_type Declaration & Initialization :
  13. double z=0.0001;
  14. double NR=0.01;
  15. int NI=11;
  16. double RF;
  17.  
  18. int main(int argc, char* argv[])
  19. {
  20. std::cout <<"\nThe Function is ' F(x)=e^(-x)+x^2 '";
  21. std::cout <<"\n";
  22.  
  23. int numElement =20;
  24. double *a,*b,*c,*d,*Fc,*Fd,I;
  25. a = new double[numElement];
  26. b = new double[numElement];
  27. c = new double[numElement];
  28. d = new double[numElement];
  29. Fc= new double[numElement];
  30. Fd= new double[numElement];
  31.  
  32. //User Specify The Interval :
  33. std::cout << "\nGive The Initian Point :" <<"\na1 =";
  34. std::cin >> a[1];
  35. std::cout << "\nGive The Final Point :" <<"\nb1 =";
  36. std::cin >> b[1];
  37.  
  38. //Find Distance Between The Starting Interval :
  39. I=(b[1]-a[1]);
  40. std::cout << "\nInterval Reduction At The Initial Iteration :"<< "\nI(1) = " << I <<"\n";
  41.  
  42.  
  43.  
  44. //Here The Beginnins Of Iteration Technique
  45. //We Introduce Two Another Points For Getting Two New Interval Of Uncertainty
  46. //First Point 'c1' And Second Point 'd1' :
  47. c[1]=b[1]-(R_Fibo()*I);
  48. std::cout << "\nPlaced A Point c1 Within The Initial Interval :"<< c[1];
  49. d[1]=a[1]+(R_Fibo()*I);
  50. std::cout <<"\nPlaced Another Point d1 Within The Initial Interval :"<<d[1];
  51. std::cout <<"\n";
  52. std::cout <<"\n";
  53.  
  54. //Showing The Starting Reduction :
  55. //----------------
  56. //----------------
  57. std::cout <<"At The First Iteration :\n";
  58. std::cout <<"The Value Of a1=" << a[1] << "\n";
  59. std::cout <<"The Value Of b1=" << b[1] << "\n";
  60. std::cout <<"The Value Of c1=" << c[1] << "\n";
  61. std::cout <<"The Value Of d1=" << d[1] ;
  62. //--------------------
  63.  
  64. //Function 'Fc1' at point 'c1' And Function 'Fd1' at point 'd1':
  65. // write a function which takes one argument and returns the value. use it here instead of explicit coding.
  66. Fc[1]=(exp(-c[1]))+(c[1]*c[1]);
  67. std::cout << "\nAt c1 The Function Value Fc1=" << Fc[1];
  68. //std::cout <<"\n";
  69. Fd[1]=(exp(-d[1]))+(d[1]*d[1]);
  70. std::cout << "\nAt d1 The Function Value Fd1=" << Fd[1];
  71. std::cout <<"\n";
  72. std::cout <<"\n";
  73. //---------------------
  74. //---------------------
  75.  
  76. double In=b[NI]-a[NI];
  77. std::cout <<"\nThe Interval Reduction At The Final Iteration :" <<"\nI(n)= " << In;
  78. std::cout<<"\n";
  79.  
  80. std::cout << std::endl;
  81. system("pause");
  82. //return 0;
  83. }
  84.  
  85. void showdata(void)
  86. {
  87. //For Accuracy Exactness Need A Small Pertubation At The Final Interval
  88. std::cout <<"\nFor Accuracy At The Final Interval, Taken The Small Perturbation z :";
  89. std::cout <<"\nTaken z = 0.0001" << "\n";
  90.  
  91. //Give The Prescribe Interval Reduction :
  92. std::cout <<"\nNeeded The Prescribe Interval Reduction :" <<"\nNR = 0.01 units";
  93. std::cout <<"\n";
  94.  
  95. //Calculate The Number Of Iteration From The Given Interval Reduction :
  96. //By Fibonacci Series
  97. std::cout <<"\nAccording To The Interval Reduction";
  98. std::cout <<"\nThe Requring Number Of Iteration :" << "\nNI = 11 times";
  99. std::cout <<"\n";
  100. std::cout <<"\n";
  101.  
  102. std::cout <<"\nBefore The Start Of Interval Reduction";
  103. std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = 0.618056";
  104. std::cout <<"\n";
  105.  
  106. }
  107.  
  108. double R_Fibo()
  109. {
  110. //Ratio of two successive terms of Fibonacci Sequence is obtained using Binet's Formula
  111. //Function (F(m-1)/Fm) Defination :
  112.  
  113. double n1=1-(sqrt((double)5));
  114. double n2=1+(sqrt((double)5));
  115. double s=(n1/n2);
  116. //cout << "\nsThe Value Of s = " << s <<"\n";
  117.  
  118. double s1=(sqrt((double)5)-1)/2;
  119. //cout << "\nThe Value Of s1 = " << s1 <<"\n";
  120.  
  121. double RF=s1*((1-pow(s,NI))/(1-pow(s,(NI+1))));
  122.  
  123. //std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = " << RF <<"\n";
  124. //std::cout << RF;
  125.  
  126. return RF;
  127.  
  128. }
  129.  
  130.  
  131.  
  132. double F_Ite()
  133. { //F_Ite Function Start
  134. //Locally Data_type Declaration And Initialization :
  135. int numElement =20;
  136. double *a,*b,*c,*d,*Fc,*Fd;
  137. a = new double[numElement];
  138. b = new double[numElement];
  139. c = new double[numElement];
  140. d = new double[numElement];
  141. Fc= new double[numElement];
  142. Fd= new double[numElement];
  143.  
  144.  
  145. for(int k=1;k<(NI-1);k++)
  146. { //Main 'for' Loop under F_Ite() Start
  147. std::cout <<"\n";
  148. system("pause");
  149. std::cout <<"\n";
  150. std::cout <<"At The "<<k+1<<" Iteration :\n";
  151.  
  152. if(Fc[k]<Fd[k])
  153. { //Outer 'if' Start
  154. a[k+1]=a[k];
  155. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  156. b[k+1]=d[k];
  157. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  158. //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]);
  159. //cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  160. if(k==(NI-1))
  161. {
  162. c[k+1]=c[k+1]+z;
  163. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  164. }
  165. else
  166. {
  167. 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]);
  168. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  169. }
  170. d[k+1]=c[k];
  171. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  172.  
  173. Fc[k+1]=(exp(-c[k+1]))+(c[k+1]*c[k+1]);
  174. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  175. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k] << "\n";
  176.  
  177. Fd[k+1]=Fc[k];
  178. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fc[k] << "\n";
  179. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  180.  
  181.  
  182. } //Outer 'if' Close
  183. else
  184. { //Outer 'else' Start
  185. a[k+1]=c[k];
  186. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  187. b[k+1]=b[k];
  188. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  189. c[k+1]=d[k];
  190. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  191. //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]);
  192. //std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  193.  
  194. if(k==(NI-1))
  195. {
  196. d[k+1]=d[k+1]+z;
  197. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  198. }
  199.  
  200. else
  201. {
  202. 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]);
  203. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  204. }
  205.  
  206.  
  207. Fc[k+1]=Fd[k];
  208. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fd[k] << "\n";
  209. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  210. Fd[k+1]=(exp(-d[k+1]))+(d[k+1]*d[k+1]);
  211. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  212. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k] << "\n";
  213.  
  214. } //Outer 'else' Close
  215. } //Main 'for' Loop Close
  216.  
  217. //Another 'if' Condition Start But Within The 'for' Loop
  218. if(Fc[10]<Fd[10])
  219. {
  220. std::cout <<"\n";
  221. std::cout <<"\nAt Final Iteration :\n";
  222. a[NI]=a[NI-1];
  223. b[NI]=d[NI-1];
  224. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  225. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  226. }
  227. else
  228. {
  229. a[NI]=c[NI-1];
  230. b[NI]=b[NI-1];
  231. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  232. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  233. }
  234.  
  235. } //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
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 32
Reputation: sdmahapatra is an unknown quantity at this point 
Solved Threads: 0
sdmahapatra sdmahapatra is offline Offline
Light Poster

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #5
Jun 16th, 2009
Originally Posted by Sky Diploma View Post
Why dont you use an array of pointers and return the array of pointers.

Will u pls help me how to do this?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 302
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 52
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #6
Jun 16th, 2009
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:
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. // pass values into your function
  5. void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd)
  6. { //Main Function Start
  7. // you could initialise your variables here, or outside of the function.
  8. // I've gone for the latter, but whatever floats your boat!
  9.  
  10. for(int k=1;k<(NI-1);k++)
  11. { //Main 'for' Loop Start
  12. std::cout <<"\n";
  13. system("pause");
  14. std::cout <<"\n";
  15. std::cout <<"At The "<<k+1<<" Iteration :\n";
  16.  
  17. if(Fc[k]<Fd[k])
  18. { //Outer 'if' Start
  19. a[k+1]=a[k];
  20. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  21. b[k+1]=d[k];
  22. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  23. //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]);
  24. //cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  25. if(k==(NI-1))
  26. {
  27. c[k+1]=c[k+1]+z;
  28. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  29. }
  30. else
  31. {
  32. 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]);
  33. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  34. }
  35. d[k+1]=c[k];
  36. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  37.  
  38. Fc[k+1]=(exp(-c[k+1]))+(c[k+1]*c[k+1]);
  39. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  40. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k] << "\n";
  41.  
  42. Fd[k+1]=Fc[k];
  43. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fc[k] << "\n";
  44. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  45.  
  46.  
  47. } //Outer 'if' Close
  48. else
  49. { //Outer 'else' Start
  50. a[k+1]=c[k];
  51. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  52. b[k+1]=b[k];
  53. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  54. c[k+1]=d[k];
  55. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  56. //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]);
  57. //std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  58.  
  59. if(k==(NI-1))
  60. {
  61. d[k+1]=d[k+1]+z;
  62. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  63. }
  64. else
  65. {
  66. 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]);
  67. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  68. }
  69.  
  70.  
  71. Fc[k+1]=Fd[k];
  72. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fd[k] << "\n";
  73. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  74. Fd[k+1]=(exp(-d[k+1]))+(d[k+1]*d[k+1]);
  75. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  76. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k] << "\n";
  77.  
  78. } //Outer 'else' Close
  79. } //Main 'for' Loop Close
  80.  
  81. //Another 'if' Condition Start But Within The 'for' Loop
  82. if(Fc[10]<Fd[10])
  83. {
  84. std::cout <<"\n";
  85. std::cout <<"\nAt Final Iteration :\n";
  86. a[NI]=a[NI-1];
  87. b[NI]=d[NI-1];
  88. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  89. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  90. }
  91. else
  92. {
  93. a[NI]=c[NI-1];
  94. b[NI]=b[NI-1];
  95. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  96. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  97. }
  98.  
  99. } //Main Function Close
  100.  
  101.  
  102. int main()
  103. {
  104. // declare your pointers outside of your function and pass them as parameters to F_Ite
  105. double *a,*b,*c,*d,*Fc,*Fd;
  106.  
  107. // you could optionally initialise them before passing them to your function
  108. int numElement =20;
  109.  
  110. a = new double[numElement];
  111. b = new double[numElement];
  112. c = new double[numElement];
  113. d = new double[numElement];
  114. Fc= new double[numElement];
  115. Fd= new double[numElement];
  116.  
  117. // now call the function
  118. F_Ite(a,b,c,d,Fc,Fd);
  119.  
  120. // Now you can cout your values, or do whatever with them
  121. // don't forget to delete them when you're done.
  122. // wherever you create something with 'new' you should
  123. // always call 'delete' when finished!
  124.  
  125. return 0;
  126. }
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.
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!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 32
Reputation: sdmahapatra is an unknown quantity at this point 
Solved Threads: 0
sdmahapatra sdmahapatra is offline Offline
Light Poster

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #7
Jun 16th, 2009
Originally Posted by ArkM View Post
1. About C4716: didn't you know that 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.



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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #8
Jun 16th, 2009
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

  1.  
  2. struct Values{ //Creates a new datatype named values
  3. double* a, *b;//SO on.
  4. }
  5.  
  6. Values func1()// function named func1 returning type Values
  7. {
  8. double *s, *z;
  9. /*Do something with s and z*/
  10. Values a1;// Now we made a variable named a1 of type value
  11. a1.a=&s; //We know that Values have a member a;
  12. a1.b=&z; //And also b, We now make them point to the local doubles
  13. return a1; //Return type of values
  14. }
  15.  
  16. int main()
  17. Values f1=func1();
  18. }
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 delete [] later.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 302
Reputation: JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough JasonHippy is a jewel in the rough 
Solved Threads: 52
JasonHippy's Avatar
JasonHippy JasonHippy is offline Offline
Posting Whiz

Re: c++ "error C4716: 'F_Ite' : must return a value"

 
0
  #9
Jun 16th, 2009
Originally Posted by Sky Diploma View Post

I personally feel that for you the best way to return your doubles is with a struct.
I second that motion!
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!
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 32
Reputation: sdmahapatra is an unknown quantity at this point 
Solved Threads: 0
sdmahapatra sdmahapatra is offline Offline
Light Poster

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

 
0
  #10
Jun 20th, 2009
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

  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4.  
  5. using namespace std; // you should not use this statement.
  6. void F_Ite(double,double,double,double,double,double);
  7. // never ever declare global data in C++
  8.  
  9. //Globally Data_type Declaration & Initialization :
  10. double z=0.0001;
  11. double NR=0.01;
  12. int NI=11;
  13. double RF;
  14.  
  15. int main(int argc, char* argv[]) // put the othe arguments for main (int argc, char* argv[])
  16. {
  17. //Result Of A Fibonacci_Search Algorithm Operation On A Given Function :
  18. std::cout <<"\nThe Function is ' F(x)=e^(-x)+x^2 '";
  19. std::cout <<"\n";
  20.  
  21. // declare your pointers outside of your function and pass them as parameters to F_Ite
  22. double *a,*b,*c,*d,*Fc,*Fd,I;
  23.  
  24. // you could optionally initialise them before passing them to your function
  25. int numElement =20;
  26.  
  27. a = new double[numElement];
  28. b = new double[numElement];
  29. c = new double[numElement];
  30. d = new double[numElement];
  31. Fc= new double[numElement];
  32. Fd= new double[numElement];
  33.  
  34. // now call the function
  35. F_Ite(a,b,c,d,Fc,Fd);
  36.  
  37. // Now you can cout your values, or do whatever with them
  38. // don't forget to delete them when you're done.
  39. // wherever you create something with 'new' you should
  40. // always call 'delete' when finished!
  41.  
  42. //User Specify The Interval :
  43. std::cout << "\nGive The Initian Point :" <<"\na1 =";
  44. std::cin >> a[1];
  45. std::cout << "\nGive The Final Point :" <<"\nb1 =";
  46. std::cin >> b[1];
  47.  
  48.  
  49. //Find Distance Between The Starting Interval :
  50. I=(b[1]-a[1]);
  51. std::cout << "\nInterval Reduction At The Initial Iteration :"<< "\nI(1) = " << I <<"\n";
  52.  
  53.  
  54. //For Accuracy Exactness Need A Small Pertubation At The Final Interval
  55. std::cout <<"\nFor Accuracy At The Final Interval, Taken The Small Perturbation z :";
  56. std::cout <<"\nTaken z = 0.0001" << "\n";
  57.  
  58. //Give The Prescribe Interval Reduction :
  59. std::cout <<"\nNeeded The Prescribe Interval Reduction :" <<"\nNR = 0.01 units";
  60. std::cout <<"\n";
  61.  
  62. //Calculate The Number Of Iteration From The Given Interval Reduction :
  63. //By Fibonacci Series
  64. std::cout <<"\nAccording To The Interval Reduction";
  65. std::cout <<"\nThe Requring Number Of Iteration :" << "\nNI = 11 times";
  66. std::cout <<"\n";
  67. std::cout <<"\n";
  68.  
  69.  
  70. system("pause"); // this is a platform specific call. do not use this.
  71.  
  72.  
  73.  
  74. //To Calculate The Ratio of two consecutive Fibo_Num (F(m-1)/Fm) :
  75. //Function (F(m-1)/Fm) Declaration :
  76. double R_Fibo();
  77. std::cout <<"\nBefore The Start Of Interval Reduction";
  78. std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = 0.618056";
  79. std::cout <<"\n";
  80.  
  81.  
  82. //Here The Beginnins Of Iteration Technique
  83.  
  84. //We Introduce Two Another Points For Getting Two New Interval Of Uncertainty
  85. //First Point 'c1' And Second Point 'd1' :
  86. c[1]=b[1]-(R_Fibo()*I);
  87. std::cout << "\nPlaced A Point c1 Within The Initial Interval :"<< c[1];
  88. d[1]=a[1]+(R_Fibo()*I);
  89. std::cout <<"\nPlaced Another Point d1 Within The Initial Interval :"<<d[1];
  90. std::cout <<"\n";
  91. std::cout <<"\n";
  92.  
  93. //Showing The Starting Reduction :
  94. //----------------
  95. //----------------
  96. std::cout <<"At The First Iteration :\n";
  97. std::cout <<"The Value Of a1=" << a[1] << "\n";
  98. std::cout <<"The Value Of b1=" << b[1] << "\n";
  99. std::cout <<"The Value Of c1=" << c[1] << "\n";
  100. std::cout <<"The Value Of d1=" << d[1] ;
  101. //Function 'Fc1' at point 'c1' And Function 'Fd1' at point 'd1':
  102. //--------------------
  103.  
  104. // write a function which takes one argument and returns the value. use it here instead of explicit coding.
  105. Fc[1]=(exp(-c[1]))+(c[1]*c[1]);
  106. std::cout << "\nAt c1 The Function Value Fc1=" << Fc[1];
  107. //std::cout <<"\n";
  108. Fd[1]=(exp(-d[1]))+(d[1]*d[1]);
  109. std::cout << "\nAt d1 The Function Value Fd1=" << Fd[1];
  110. std::cout <<"\n";
  111. std::cout <<"\n";
  112. //---------------------
  113. //---------------------
  114.  
  115. //system("pause");
  116.  
  117. // this must be defined outside of main and called here explicitly.
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. double In=b[NI]-a[NI];
  125. std::cout <<"\nThe Interval Reduction At The Final Iteration :" <<"\nI(n)= " << In;
  126. std::cout<<"\n";
  127.  
  128. delete [] a;
  129. delete [] b;
  130. delete [] c;
  131. delete [] d;
  132. delete [] Fc;
  133. delete [] Fd;
  134.  
  135.  
  136. std::cout << std::endl;
  137. system("pause");
  138. //return 0;
  139. }
  140.  
  141.  
  142.  
  143. //Ratio of two successive terms of Fibonacci Sequence is obtained using Binet's Formula
  144. //Function (F(m-1)/Fm) Defination :
  145. double R_Fibo()
  146. {
  147. double n1=1-(sqrt((double)5));
  148. double n2=1+(sqrt((double)5));
  149. double s=(n1/n2);
  150. //cout << "\nsThe Value Of s = " << s <<"\n";
  151.  
  152. double s1=(sqrt((double)5)-1)/2;
  153. //cout << "\nThe Value Of s1 = " << s1 <<"\n";
  154.  
  155. double RF=s1*((1-pow(s,NI))/(1-pow(s,(NI+1))));
  156.  
  157. //std::cout << "\nThe Ratio of two consecutive Fibo_Num :"<<"\nRF = " << RF <<"\n";
  158. //std::cout << RF;
  159.  
  160. return RF;
  161.  
  162. }
  163.  
  164.  
  165. // pass values into F_Ite() function
  166. void F_Ite(double *a, double *b, double *c, double *d, double *Fc, double *Fd)
  167. { //F_Ite Function Start
  168.  
  169. for(int k=1;k<(NI-1);k++)
  170. { //Main 'for' Loop Start
  171. std::cout <<"\n";
  172. system("pause");
  173. std::cout <<"\n";
  174. std::cout <<"At The "<<k+1<<" Iteration :\n";
  175.  
  176. if(Fc[k]<Fd[k])
  177. { //Outer 'if' Start
  178. a[k+1]=a[k];
  179. cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  180. b[k+1]=d[k];
  181. cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  182. //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]);
  183. //cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  184. if(k==(NI-1))
  185. {
  186. c[k+1]=c[k+1]+z;
  187. cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  188. }
  189. else
  190. {
  191. 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]);
  192. cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  193. }
  194. d[k+1]=c[k];
  195. cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  196.  
  197. Fc[k+1]=(exp(-c[k+1]))+(c[k+1]*c[k+1]);
  198. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  199. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k] << "\n";
  200.  
  201. Fd[k+1]=Fc[k];
  202. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fc[k] << "\n";
  203. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  204.  
  205.  
  206. } //Outer 'if' Close
  207. else
  208. { //Outer 'else' Start
  209. a[k+1]=c[k];
  210. std::cout <<"The Value Of a" << k+1 << "=" << a[k+1] << "\n";
  211. b[k+1]=b[k];
  212. std::cout <<"The Value Of b" << k+1 << "=" << b[k+1] << "\n";
  213. c[k+1]=d[k];
  214. std::cout <<"The Value Of c" << k+1 << "=" << c[k+1] << "\n";
  215. //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]);
  216. //std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  217.  
  218. if(k==(NI-1))
  219. {
  220. d[k+1]=d[k+1]+z;
  221. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  222. }
  223.  
  224. else
  225. {
  226. 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]);
  227. std::cout <<"The Value Of d" << k+1 << "=" << d[k+1] << "\n";
  228. }
  229.  
  230.  
  231. Fc[k+1]=Fd[k];
  232. //std::cout <<"The Value Of Fc" << k+1 << "=" << Fd[k] << "\n";
  233. std::cout <<"The Value Of Fc" << k+1 << "=" << Fc[k+1] << "\n";
  234. Fd[k+1]=(exp(-d[k+1]))+(d[k+1]*d[k+1]);
  235. std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k+1] << "\n";
  236. //std::cout <<"The Value Of Fd" << k+1 << "=" << Fd[k] << "\n";
  237.  
  238. } //Outer 'else' Close
  239. } //Main 'for' Loop Close
  240.  
  241. //Another 'if' Condition Start But Within The 'for' Loop
  242. if(Fc[10]<Fd[10])
  243. {
  244. std::cout <<"\n";
  245. std::cout <<"\nAt Final Iteration :\n";
  246. a[NI]=a[NI-1];
  247. b[NI]=d[NI-1];
  248. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  249. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  250. }
  251. else
  252. {
  253. a[NI]=c[NI-1];
  254. b[NI]=b[NI-1];
  255. std::cout <<"The Value Of a11 =" << a[NI] << "\n";
  256. std::cout <<"The Value Of b11 =" << b[NI] << "\n";
  257. }
  258.  
  259. } //F_Ite Function Close
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC