I am writing a code where user inputs starting value, maximum value and step value. I calculate the results properly and all the formulas are correct, but there is one problem. I am unable to stop the loop so that my answers are displayed properly. When I run, it just starts the loop and I get lots of answers spammed on screen.
#include <stdio.h>
#include <math.h>
float funqcia(float x, float y, float k);
int main()
{
float y;
float A;
float B;
float H;
float x;
float t;
int e=0;
int N=15;
int k = 0;
while(e==0)
{
printf("enter starting value here: ");
scanf("%fl",&A);
printf("enter maximum value: ");
scanf("%fl", &B);
printf("enter step: ");
scanf("%fl", &H);
if(B > A)
{
e=1;
}
else
{
printf("Sorry, stopping value should be higher than starting value.");
}
}
while(e==1)
{
printf("%s","_________________________________________________");
printf("%s","\n");
printf("%s","| |");
printf("%s","\n");
printf("%s","| Results are shown below |");
printf("%s","\n");
printf("%s","| |");
printf("%s","\n");
printf("%s","--------------------------------------------------");
printf("%s","\n");
t=0;
/*for(int i=0;i<N;i++)
{
if(i>0)
{
if (B<=y)
{
break;
}
t=pow(2,i)*pow(H,i-1);
x=x+t;
printf("%s","| ");
printf("%fl",x);
printf("%s"," | ");
funqcia(x,y);
printf("%s","\n");
}
else
{
if (B<=y)
{
break;
}
x=A;
printf("%s","| ");
printf("%fl",x);
printf("%s"," | ");
funqcia(x,y);
printf("%s","\n");
}
}*/
for (int i=0;i<N;i++)
{
t=pow(2,i)*pow(H,i-1);
x=x+t;
if (i == 0)
{
x=A;
}
y=funqcia(x,y,k);
if (B<=k)
{
break;
}
else
{
printf("x=%fl\ty=%fl", x,y);
//}
}
}
}
}
float funqcia(float x, float y, float k)
{
y=((3+exp(x-1))/(1+pow(x,2)*(3-tan(x))));
if(isinf(y))
{
printf("this is infinity");
}
else
{
printf("y: %fl",y);
}
k=y;
return k;
}