当用户输入 1,2 或 3 时,程序退出而不扫描 else if 语句 block 内的数量。
如何扫描 if 或 else if 语句内部?
if (num==4)
{
printf("exiting");
goto end;
}
else
{
if (num=='1')
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*kmstomiles;
printf("the value of the second unit is %f",second);
}
else if (num=='2')
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*inchestofeet;
printf("the value of the second unit is %f",second);
}
else if (num=='3')
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*cmtoinches;
printf("the value of the second unit is %f",second);
}
最佳答案
请使用下面的代码,
if (num==4)
{
printf("exiting");
goto end;
}
else
{
if (num==1)
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*kmstomiles;
printf("the value of the second unit is %f",second);
}
else if (num==2)
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*inchestofeet;
printf("the value of the second unit is %f",second);
}
else if (num==3)
{
printf("enter the value of the first unit\n");
scanf("%f",&first);
second=first*cmtoinches;
printf("the value of the second unit is %f",second);
}
关于c - 我无法执行在 else if 语句中包含用户输入的整数的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56721137/