the first thing is that your code is very unreadable....
you should stick with some formatting... (i think its called Best Practices...) just look at the codes here in this site and try to figure out a formatting style for you, so you will be able to read your code more easily...
i cannot see the function "f" defined in here...
what you have done is just write the codes of your function in the "main" function, which always returns type "int"... normally we set the return value to "0"(zero) so that the system knows that the program worked successfully.. ( see EXIT_SUCCESS in the library stdlib.h , just search for it in google)...
i guess,
what your were thinking is that this is your function "f", and of course the function "f" returns "double".... but you have written it not inside funcion "f" , but inside function "main"...
this must be what you were trying to do,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <fstream.h>
#include <iomanip.h>
#include <math.h>
#include <iostream.h>
#include <stdlib.h>
using namespace std;
double f(double);
int main()
{
double returnValueOfF;
returnValueOfF = f();
return 0;
}
double f(double parameter)
{
double a,b,delx,n,area,i,x;
ofstream output ("e:result17.dat'");
cout<<"..."<<endl;
output<<"..."<<endl;
a=2.0;
b=5.0;
cout<<" Enter a value for n : "<<endl;
output<<" Enter a value for n : "<<endl;
cin>>n;
cout<<" n= "<<n<<endl;
output<<" n= "<<n<<endl;
area=0;
delx=(b-a)/n;
for(i=0;i<n;++i)
{
area=area+f(a+i*delx)*delx;
}
cout<<" The area of lower limit is = "<<area<<endl;
output<<" The area of lower limit is = "<<area<<endl;
for(i=1;i<=n;++i)
area=area+f(a+i*delx)*delx;
cout<<" The area of upper limit is = "<<area<<endl;
system("PAUSE");
return 0.6*pow(x,2)+2;
}
|
ps. see how nice the code looks with some formatting... see how nicely it is readable... it only lacks commenting....
please, never forget to add comments and white-spaces (newlines, tabs, spaces ) to your code.... it will make your life easier...