C语言程序错误illegal indirection// c.cpp :Defines the entry point for the console application.//华氏温度转换为摄氏温度#include "stdafx.h"#include "stdio.h"#define FREEZING_PT 32.0f;#define SCALE_FACTOR (5.0 / 9.0f)int main(){\x05floa

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/27 21:23:24
C语言程序错误illegal indirection// c.cpp :Defines the entry point for the console application.//华氏温度转换为摄氏温度#include

C语言程序错误illegal indirection// c.cpp :Defines the entry point for the console application.//华氏温度转换为摄氏温度#include "stdafx.h"#include "stdio.h"#define FREEZING_PT 32.0f;#define SCALE_FACTOR (5.0 / 9.0f)int main(){\x05floa
C语言程序错误illegal indirection
// c.cpp :Defines the entry point for the console application.
//华氏温度转换为摄氏温度
#include "stdafx.h"
#include "stdio.h"
#define FREEZING_PT 32.0f;
#define SCALE_FACTOR (5.0 / 9.0f)
int main()
{
\x05float fahrenheit,celsius;\x05//声明变量fahrenheit和celsius
\x05printf("Enter Fahrenheit temperature:");
\x05scanf("%f",&fahrenheit);\x05\x05//获取华氏温度
\x05celsius=( fahrenheit - FREEZING_PT )* SCALE_FACTOR;\x05\x05\x05//计算变量celsius的值
\x05printf("Celsius equivalent:%.1f\n",celsius);\x05\x05//显示显示摄氏温度
\x05
\x05return 0;\x05\x05//返回操作系统
}
--------------------Configuration:c - Win32 Debug--------------------
Compiling...
c.cpp
f:\cccc\c\c.cpp(19) :error C2143:syntax error :missing ')' before ';'
f:\cccc\c\c.cpp(19) :error C2059:syntax error :')'
f:\cccc\c\c.cpp(19) :error C2100:illegal indirection
执行 cl.exe 时出错.
c.exe - 1 error(s),0 warning(s)
请问上面这段代码错在哪了?求指正!

C语言程序错误illegal indirection// c.cpp :Defines the entry point for the console application.//华氏温度转换为摄氏温度#include "stdafx.h"#include "stdio.h"#define FREEZING_PT 32.0f;#define SCALE_FACTOR (5.0 / 9.0f)int main(){\x05floa
#include "stdafx.h"
#include "stdio.h"
#define FREEZING_PT 32.0f; //此处多了一个分号
#define SCALE_FACTOR (5.0 / 9.0f)
这里用的是宏定义,在C语言里,宏采用的是一种类似替换的原则,比如你上面的程序,C语言实际执行的是:
celsius=( fahrenheit - 《32.0f;》 )* SCALE_FACTOR;
请注意《》内的内容,这里宏“傻瓜”似的把分号替换了过来,所以错误会显示在这里