C 为什么可以';我不能得到输入值吗?

C 为什么可以';我不能得到输入值吗?,c,C,我无法将输入值分配给bj。 例如,当我输入756时,我希望同时得到UTC:2356,但是计算机同时给我UTC:1600 #include <stdio.h> int main() { int bj; scanf("Input a BJT: %d", &bj); if(bj>=0&&bj<=2359&&bj%100<60) { if(bj<800) b

我无法将输入值分配给
bj
。 例如,当我输入
756
时,我希望同时得到
UTC:2356
,但是计算机同时给我
UTC:1600

#include <stdio.h>
int main()
{
    int bj;
    scanf("Input a BJT: %d", &bj);
    if(bj>=0&&bj<=2359&&bj%100<60)
    {
        if(bj<800)
            bj+=1600;
        else
            bj-=800;
        printf("UTC at the same time: %d",bj);
    }
    else
        ;
    return 0;
}
#包括
int main()
{
int北京;
scanf(“输入一个BJT:%d”、&bj);
如果(bj>=0&&bj
您在某种程度上混淆了
printf
scanf
函数。
scanf
指定了输入内容,因此您不希望输出内容出现在其中,也不希望输出内容出现在您的输入中

像这样把他们分开

printf("Input a BJT:\n");
scanf("%d", &bj);
这条线乱七八糟。请像这样使用它:

printf("Input a BJT: ");
scanf("%d", &bj);

选中此选项有两种解决方案:

一,

二,。
当您输入时,您应该在输入
bj
的值之前输入
input aBJT:
。例如,我希望
bj
等于
756
,因此我输入
input aBJT:756

scanf(“输入aBJT:%d,&bj”);
-->
printf(“输入aBJT:”);scanf(%d,&bj);
这是1时得到的结果)不要初始化自动局部变量2)如果(bj>=0&&bj=0)&(bj)避免空格,不要检查
scanf()
的返回值。多放一些空格,使代码可读性挑剔:“canf指定输入应该是什么”…实际上是格式字符串
scanf("Input a BJT: %d", &bj);
printf("Input a BJT: ");
scanf("%d", &bj);
printf("Input a BJT:\n");
scanf("%d", &bj);