hi
i do my homework.
but i cant write it in class ... please help:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int a=1;
int counter =1;
int total=1;
int s=1;
int m=1;
int x;
cout<<"enter value of x :";
cin>>x;
while(counter <= x)
{
while( a<=counter)
{
s*=x;
m*=counter;
a++;}
total+=(s/m);
counter++;
}
cout<<"total = : "<<total;
getch();
return 0;
}
Several different issues here. First, the important variables used in the calculation need to be of type double, not int.
Since this is the summation of an infinite series, we need some way to determine how many terms to include. One way is to ask the user to enter that value. The more terms we use, the more accurate result - but beyond a certain point the later terms become too small to make a difference.
And there is a logic error, only a single loop is required, to iterate through each of the terms of the series.