# 简单的 C 编码问题：跳过 Printf 并跳过用户输入

[英]Simple C Coding Problem: Skipping Over Printf and Skipping User Input

I want to have the second line of code to have the user input the Fahrenheit not the Celsius twice.我想让第二行代码让用户输入华氏度而不是摄氏度两次。 The int main() code is correct and the output number is correct but the user does not input the Fahrenheit. int main() 代码是正确的，output 数字是正确的，但用户没有输入华氏温度。 How do I fix this?我该如何解决？ enter image description here在此处输入图像描述

What is expected is that the user inputs the Fahrenheit and the code continues.预期的是用户输入华氏度并且代码继续。 I do not want the output to skip over lines 12-14.我不希望 output 跳过第 12-14 行。 I don't know how to fix this.我不知道如何解决这个问题。 I expect that once the user inputs Fahrenheit the code will continue to run as it currently does我希望一旦用户输入华氏度，代码将继续像当前一样运行

``````#include <stdio.h>
#include <math.h>

{
double temp_celcius, temp;

printf("Enter the current air temperature(in Celcius): ");
scanf(" %lf", &temp_celcius);
return(temp_celcius);

printf("Enter the current air temperature(in Fahrenheit): ");
scanf(" %lf", &temp);
return (temp);
}

int main()

{

double temp_celcius, spsound_1,spsound_convert_1,temp,
spsound,spsound_convert;

{
spsound_1 = 1086 * sqrt(((5 * (temp_celcius*1.8+32)) + 297)
/ 247);
spsound_convert_1=spsound_1*1.09728;

spsound = 1086 * sqrt(((5 * temp) + 297) / 247);
spsound_convert=spsound*1.09728;

printf("\nThe speed of sound at %.2f degrees Celcius is %.2f
ft/s.\n", temp_celcius, spsound_1);
printf ("The speed of sound at this temperature in Celciusis
equivalent to %.2f km/h.\n\n", spsound_convert_1);
printf("The speed of sound at %.2f degrees Fahrenheit is %.2f
ft/sec.\n", temp, spsound);
printf ("The speed of sound at this temperature in Fahrenheit
is equivalent to %.2f km/h.\n", spsound_convert);
}
return(0);
}
``````

You used used `return` twice in the function so that it `won't go ahead` for asking the fahrenhiet question.您在 function 中使用了`return`两次，这样它就`won't go ahead` go 询问华氏度问题。 Whenever `return` is encountered while compiling it terminates the function there and there only.每当在编译时遇到`return`时，它只会在那里终止 function。

Now what you can do is that just make another `function` for fahrenhiet and copy paste the fahrenhit part in it.现在你可以做的就是为华氏温度制作另一个`function`并将华氏温度部分复制粘贴到其中。

``````#include <stdio.h>
#include <math.h>
double temp_celcius;
printf("Enter the current air temperature(in Celcius): ");
scanf(" %lf", &temp_celcius);
return(temp_celcius);
}

double temp;
printf("Enter the current air temperature(in Fahrenheit): ");
scanf(" %lf", &temp);
return (temp);
}

int main()

{

double temp_celcius, spsound_1,spsound_convert_1,temp,
spsound,spsound_convert;

{
spsound_1 = 1086 * sqrt(((5 * (temp_celcius*1.8+32)) + 297)
/ 247);
spsound_convert_1=spsound_1*1.09728;

spsound = 1086 * sqrt(((5 * temp) + 297) / 247);
spsound_convert=spsound*1.09728;

printf("\nThe speed of sound at %.2f degrees Celcius is %.2f ft/s.\n", temp_celcius, spsound_1);
printf ("The speed of sound at this temperature in Celciusis equivalent to %.2f km/h.\n\n", spsound_convert_1);
printf("The speed of sound at %.2f degrees Fahrenheit is %.2f ft/sec.\n", temp, spsound);
printf ("The speed of sound at this temperature in Fahrenheit is equivalent to %.2f km/h.\n", spsound_convert);
}
return(0);
}
``````

Hope it helps;!!希望能帮助到你;！！ ;) ;)