I have a problem referring to Geometric progression

Using a few mathematics formula I have to compare the value En that I calculate using

Sinfinite and Sn.

This value En(which determines accuracy of the calculated number I believe) should than be compared to an arbitrary value E.

When En becomes smaller than E, the program should be terminated and the calculated value should be printed on the screen.

The sum is always 0 when I try to run this program.

any ideas?

thanks in advance

PS: It has to be in a while loop, not in a for.

```
#include <stdio.h>
#include <math.h>
int main(void)
{
double a;
int N = 0;
double r;
int n = 0;
double Sn = 0;
double Sinfinite;
double En = 0;
double E;
printf("Value of a: ");
scanf("%lf", &a);
printf("Value of r: ");
scanf("%lf", &r);
printf("Value of E: ");
scanf("%lf", &E);
/*Comparing En with E*/
while ( En>=E){
Sn += a*pow(r, n);
n++;
}
Sinfinite = a/(1-r);
En = Sinfinite - Sn;
printf("Sum is %0.3f\t", Sn);
printf("Sinfinite = %.3f", Sinfinite);
printf("En = %.3f\t", En);
printf("N = %d", N);
return 0;
}
```