c++ - Returning in double functions -
double interpolation(int input, vector<int>&a, vector<double>&b) { for(int i=0;i<a.size();++i) { if(input==a.at(i)) return b.at(i); } for(int i=0;i<a.size()-1;++i) { if(input>a.at(i)&&input<a.at(i+1)) { int low=i; int high=i+1; double m= b.at(low); int n= input-a.at(low); int p= a.at(high) - a.at(low); double q= b.at(high) - b.at(low); double fp = (m+n) / (p*q); return fp; } } }
i keep getting warning: control reaches end of non-void function [-wreturn-type] } message.
i know has way i'm returning value function. purpose of function calculate f(b) = f(a) + (b - a)/(c - a)(f(c) - f(a)). it's hard explaining equation is, yeah return trick think.
you getting warning because code not return value when size of 'a' vector zero. should return 0 in event, unless error code more appropriate.
Comments
Post a Comment