1. Description of the problemThe problem shows as shown in the picture: All Ides are VS2010.
Source code: Source code is a program that converts Fahrenheit temperature to Celsius.
#include <stdio.h>
//void fahr_celsius ()
int main ()
{
//int Fahr, Celsius;
int lower, upper, step;
lower = 0;
upper =;
Step =;
printf ("Hello world!\n");
int Fahr, celsius;
Fahr = lower;
while (Fahr<=upper)
{
Celsius = 5 * (fahr-32)/9;
printf ("%d\t%d\n", Fahr, Celsius);
Fahr = Fahr + step;
}
return 0;
}
2. Problem reason in C language, all variables must be declared before use. A declaration is usually placed at the beginning, before any executable statement. Declares a property that describes a variable, consisting of a type name and a variable table. This is because the variable declaration statement on line 12th is placed after the executable statement.
3. Problem solvingPut all the variable declarations before all executable statements. The modified code is as follows:
#include <stdio.h>
int main ()
{
int fahr, celsius;
int lower, upper, step;
lower = 0;
upper =;
Step =;
printf ("Hello world!\n");
int Fahr, celsius;
Fahr = lower;
while (Fahr<=upper)
{
Celsius = 5 * (fahr-32)/9;
printf ("%d\t%d\n", Fahr, Celsius);
Fahr = Fahr + step;
}
return 0;
}
4. Summary of Issues
Although this question is the C language stipulation, but this question mainly appears in the compile phase, by the compiler explanation, in VS2017 is not likely to appear this problem, but in VS2010 can appear this kind of problem.