C编程无法结束循环

C programming can't end loop

我正在编写一个代码,用户可以在其中输入起始值、最大值和步长值。我正确地计算了结果并且所有的公式都是正确的,但是有一个问题。我无法停止循环以便正确显示我的答案。当我 运行 时,它只是开始循环,我在屏幕上收到大量垃圾邮件答案。

#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;
}

您似乎在程序开始时将变量 e 初始化为 0。你有一个检查 while(e==0),当 B>A 条件为真时,e 现在变为 1。接下来您有 while(e==1) 和一些代码来显示计算和结果,这里 e 的值永远不会从 1 变为其他值。因为它总是 1,while 条件给它一个绿色信号来继续循环直到无穷大,并以某种方式弄乱屏幕上的结果。