"[Error] pointer value used where a floating point value was expected" 如何解决此错误?
"[Error] pointer value used where a floating point value was expected" How to solve this error?
我的代码在下面我想在以下代码中将华氏度转换为摄氏度,但是我会遇到错误吗?有人知道如何解决此错误吗?
#include <stdio.h>
int main()
{
int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
double celcius;
int i;
for(i=0;i<16;i++)
{
celcius = ((float)(5/9) + (float)(frnhet-32));
printf("celcius = %f",celcius);
}
return 0;
}
您错过了代码中的frnhet索引。请参考以下代码 -
#include <stdio.h>
int main()
{
int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
double celcius;
int i;
for(i=0;i<16;i++)
{
celcius = ((float)(5/9) + (float)(frnhet[i]-32));
printf("celcius = %f",celcius);
}
return 0;
}
请更改行
celcius = ((float)(5/9) + (float)(frnhet-32));
to
celcius = ((float)(5/9) + (float)(frnhet[i]-32));
您错过了访问frnht
数组的索引
#include <stdio.h>
int main()
{
int frnhet[]={0,20,40,60,80,100,120,140,160,180,200,220,240,260,280,300};
double celcius;
int i;
for(i=0;i<16;i++)
{
celcius = ((float)(5/9) + (float)(frnhet[i]-32));
printf("celcius = %f",celcius);
}
return 0;
}
在celcius = ((float)(5/9) + (float)(frnhet-32));
中,您将通过指针将其传递给浮点值除外。用于传递值,请使用celcius = ((float)(5/9) + (float)(frnhet[i]-32));
frnhet
是一个数组,在表达式frnhet-32
中,它将转换为指针转换为其第一个元素。将frnhet-32
更改为frnhet[i]-32
。
celcius = (5.0/9 + frnhet[i]-32);
您的错误在这里:
celcius = ((float)(5/9) + (float)(frnhet-32));
它必须是 frnhet[i]
celcius = ((float)(5 / 9) + (float)(frnhet[i] - 32));
相关文章:
- 运行同一解决方案的另一个项目的项目
- Project Euler问题4的错误解决方案
- Ardunio UNO解决了多个重叠的定时器循环
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 两个文件使用彼此的功能-如何解决
- 计算每个节点的树高,帮助我解释这个代码解决方案
- Python中的for循环与C++有何不同
- 如何解决"invalid conversion from 'char' to 'const char*'"
- 在java中解决这段代码时面临循环中的问题
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 难以理解某些人解决IOI问题的源代码
- visual c++,如何获取解决方案目录中的代码
- 如何解决错误:SCIP C++中的 SCIP 阶段无效 <10>
- 节俭并发:未解决的外部问题
- IpOpt拒绝解决不受约束的问题
- 如何解决这个超硬恒星的创造问题
- 如何解决类成员函数中的"return a value"错误?
- "[Error] pointer value used where a floating point value was expected" 如何解决此错误?