Source code display: Source code is a Fahrenheit to Celsius temperature of the program.
#include <stdio.h>
//void Fahr_Celsius()
int main()
{
//int fahr, celsius;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
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. Cause of the problem
In C, all variables must be declared before they are used. Declarations are usually placed at the beginning, before any executable statement. Declare the properties used to describe variables, which consist of a type name and a variable scale.
Here because the variable declaration statement on line 12 is placed after the executable statement.
3. Problem solving
Place all 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 = 300;
step = 20;
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. Problem summary
Although this problem is a stipulation of C language, it mainly appears in the compilation stage, which is interpreted by the compiler. This problem will not appear in VS2017, but will appear in VS2010.
Read More:
- Solutions to error c2143: syntax error: missing ‘;’ before ‘type’ in C + + program compilation
- Error c2143: syntax error: missing ‘;’ before ‘type’
- winnt.h C2146 error C2146: syntax error : missing ‘;’ before identifier ‘PVOID64’
- error C2146: syntax error : missing ‘;’ before identifier ‘fd’
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
- Error c2137 of C language: empty character constant (Fixed)
- [Solved] Dev-C++ [Error] ‘for‘ loop initial declarations are only allowed in C99 or C11 mode
- C / C + + library function (tower / tower) realizes the conversion of letter case
- C++:error C2228: left of ‘.str’ must have class/struct/union
- C++ : [Error] ‘ostream’ does not name a type
- Differences between length() size() and C strlen() of C + + string member functions
- Solution to the flash of running result of dev C / C + +
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- ninja Compiling the C compiler identification source file CMakeCCompilerId.c failed
- C / C + + error handling (document): unhandled exception: 0xc0000005: access violation while reading location 0x00000000
- Solution to the problem of no C / C + + option in the new project of eclipse
- C + + common errors: “error: XXX in namespace ‘STD’ does not name a template type”
- VS2010 library function problem: objidl. H (11266): error c2061: syntax error: identifier ‘__ RPC__ out_ xcount_ part’
- Debugging failed under vscode Ubuntu, unable to open libc-start. C raise. C, etc