简单计算器的运行 在操作完一次后可以继续再次运行/退出

问题遇到的现象和发生背景

运行程序出现错误 但是不知道该如何解决

问题相关代码,请勿粘贴截图
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int x,y;
double a,b;
void plus(double a,double b)
{
    printf("%.5f + %.5f=%.5f\n",a,b,a+b);
}
void minus(double a,double b)
{
    printf("%.5f - %.5f=%.5f\n",a,b,a-b);
}
void multiply(double a,double b)
{
    printf("%.5f * %.5f=%.5f\n",a,b,a*b);
}
void divide(double a,double b)
{
    printf("%.5f / %.5f=%.5f\n",a,b,a/b);
}
void Interface()
{
    printf("--------------------------------\n");
    printf("|          实用计算器          |\n");
    printf("|            1-加法            |\n");
    printf("|            2-减法            |\n");
    printf("|            3-乘法            |\n");
    printf("|            4-除法            |\n");
    printf("|            0-退出            |\n");
    printf("--------------------------------\n");
    printf("    你想要进行哪一种计算(0-4) \n");
}
void input()
{
    printf("请输入第一个数字:");
    scanf("%lf\n",&a);
    printf("请输入第二个数字:");
    scanf("%lf\n",&b);
}
int main(void)
{
    int c=0;
    Interface();
    do
    {

        do
        {
            scanf("%d",&x);
        }
        while(x<0||x>4);
        if(x==0)
            break;
        else if(x==1)
            {
                input();
                plus(a,b);
            }
        else if(x==2)
            {
                input(a,b);
                minus(a,b);
            }
        else if(x==3)
            {
                input(a,b);
                multiply(a,b);
            }
        else
            {
                input(a,b);
                divide(a,b);
            }
        printf("是否继续计算?y 继续 n 退出\n");
        scanf("%d",&y);
        if(y=='y')
            c=1;
        else if(y=='n')
            break;
    }
    while(c);
    return 0;

}


运行结果及报错内容

死循环 请输入第一个数字处会连续输入两次

我想要达到的结果

解决代码问题 正确运行

修改处见注释,供参考:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
char x, y;       //int x, y;
double a, b;
void plus(double a, double b)
{
    printf("%.5f + %.5f=%.5f\n", a, b, a + b);
}
void minus(double a, double b)
{
    printf("%.5f - %.5f=%.5f\n", a, b, a - b);
}
void multiply(double a, double b)
{
    printf("%.5f * %.5f=%.5f\n", a, b, a * b);
}
void divide(double a, double b)
{
    if (b != 0)                  //修改
        printf("%.5f / %.5f=%.5f\n", a, b, a / b);
    else
        printf("intput error\n");
}
void Interface()
{
    printf("--------------------------------\n");
    printf("|          实用计算器          |\n");
    printf("|            1-加法            |\n");
    printf("|            2-减法            |\n");
    printf("|            3-乘法            |\n");
    printf("|            4-除法            |\n");
    printf("|            0-退出            |\n");
    printf("--------------------------------\n");
    printf("    你想要进行哪一种计算(0-4) \n");
}
void input()
{
    printf("请输入第一个数字:");
    scanf("%lf", &a);         //scanf("%lf\n", &a);
    printf("请输入第二个数字:");
    scanf("%lf", &b);         //scanf("%lf\n", &b);
}
int main(void)
{
    int c = 0;
    //Interface(); 
    do
    {
        Interface(); //修改
        do
        {
          scanf("%d", &x);
        } while (x < 0 || x>4);
        if (x == 0)
            break;
        else if (x == 1)
        {
            input();
            plus(a, b);
        }
        else if (x == 2)
        {
            input();    //input(a, b);
            minus(a, b);
        }
        else if (x == 3)
        {
            input(); //input(a, b);
            multiply(a, b);
        }
        else
        {
            input(); //input(a, b);
            divide(a, b);
        }
        printf("是否继续计算?y 继续 n 退出\n");
        scanf(" %c", &y);    //scanf("%d", &y);
        if (y == 'y')
            c = 1;
        else if (y == 'n')
            break;
    } while (c);
    return 0;
}


把scanf里面的\n删掉


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int x;
char s[2];
double a,b;
void plus(double a,double b)
{
    printf("%.5f + %.5f=%.5f\n",a,b,a+b);
}
void minus(double a,double b)
{
    printf("%.5f - %.5f=%.5f\n",a,b,a-b);
}
void multiply(double a,double b)
{
    printf("%.5f * %.5f=%.5f\n",a,b,a*b);
}
void divide(double a,double b)
{
    printf("%.5f / %.5f=%.5f\n",a,b,a/b);
}
void Interface()
{
    printf("--------------------------------\n");
    printf("|          实用计算器          |\n");
    printf("|            1-加法            |\n");
    printf("|            2-减法            |\n");
    printf("|            3-乘法            |\n");
    printf("|            4-除法            |\n");
    printf("|            0-退出            |\n");
    printf("--------------------------------\n");
    printf("    你想要进行哪一种计算(0-4) \n");
}
void input()
{
    printf("请输入第一个数字:");fflush(stdout);
    scanf("%lf",&a);
    printf("请输入第二个数字:");fflush(stdout);
    scanf("%lf",&b);
}
int main()
{
    int c=0;
    do {
        Interface();
        do {
            rewind(stdin);
            scanf("%d",&x);
        } while (x<0 || x>4);
             if (x==0) break;
        else if (x==1) { input(); plus    (a,b); }
        else if (x==2) { input(); minus   (a,b); }
        else if (x==3) { input(); multiply(a,b); }
        else   /*x==4*/{ input(); divide  (a,b); }
        printf("是否继续计算?y 继续 n 退出\n");
        scanf("%1s",s);
             if (s[0]=='y') c=1;
        else if (s[0]=='n') break;
    } while(c);
    return 0;
}