gpt4 book ai didi

c++ - 为什么编译器说 'Illegal use of floating point'?

转载 作者:行者123 更新时间:2023-12-03 09:14:51 27 4
gpt4 key购买 nike

我是初学者级程序员。我编写了以下代码,通过将面积和半径存储在数组中来计算球体的面积。

#include <iostream.h>
#include <conio.h>
#define PI 3.1415

float findArea(float radius);

void main()
{
clrscr();
float radius[50], area[50];
int i=0;
cout<<"Enter radius of football, 0 to quit ";
cin>>radius[i];
area=findArea(radius[i]); //Compiler indicates error in this line
cout<<area;

while (radius[i]!=0)
{
++i;
cout<<"\nEnter the radius of football, press 0 to quit ";
cin>>radius[i];
area=findArea(radius[i]); //And in this line
cout<<area[i];
}
getch();
}

float findArea(float radius)
{
return 4 * PI * radius * radius;
}

我得到的错误是“非法使用浮点数”。我的代码有什么问题。请帮忙。

最佳答案

这条线

area=findArea(radius[i]);
area是一个数组-也许 area[i]是您想要的

关于c++ - 为什么编译器说 'Illegal use of floating point'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24971891/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com