can we convert this int o a program using functions?

#include<iostream.h>
#include<math.h>
void main()
{
int i,n;
float x,sum=0;

cout<<"x+x^2/2+x^3/3+.....+x^n/n";
cout<<"\nEnter value of x and n:";
cin>>x>>n;

for(i=1;i<=n;++i)
sum+=pow(x,i)/i;

cout<<"\nsum="<<sum;

}
Pleaseelaborate, what the problem is.
The obvious candidate for a separate function is this:
1
2
for(i=1;i<=n;++i)
sum+=pow(x,i)/i;


I notice the use of type float. I would recommend the use of type double instead. Then the function declaration would look something like this:

double sumSeries(double x, double n);

Functions are covered in the tutorial here:
http://www.cplusplus.com/doc/tutorial/functions/
Topic archived. No new replies allowed.