凯风自北来 发表于 2015-7-8 10:15:46

求助:编程报错invalid operands of types 'float' and 'int' to binary 'operator^'

本帖最后由 凯风自北来 于 2015-7-8 10:17 编辑

之前编程的时候几个量都是整型的,后来为精确起见改成浮点型,但是就报错了,请大神帮忙看下问题在哪里
arduino IDE提示
_1.ino: In function 'void setup()':
_1:18: error: invalid operands of types 'float' and 'int' to binary 'operator^'
_1:20: error: invalid operands of types 'float' and 'int' to binary 'operator^'
invalid operands of types 'float' and 'int' to binary 'operator^'

#include <AccelStepper.h>
AccelStepper stepper1(1, 9, 8);
AccelStepper stepper2(1, 7, 6);
floatflowrate1=17;            
floatdiameter1=8.24;            
intpitch1=1;                  
float area1;                     
float velocity1;   
floatflowrate2=17;            
float diameter2=8.24;            
intpitch2=1;                  
float area2;                     
float velocity2;
int pos1 = 3600;
int pos2 = 5678;
void setup()
{
   area1=3.14*((diameter1/2)^2);   
   velocity1=(flowrate1/area1)*80/3;
    area2=3.14*((diameter2/2)^2);   
   velocity2=(flowrate2/area2)*80/3;
   stepper1.setMaxSpeed(velocity1);
   stepper1.setAcceleration(1000);
   stepper2.setMaxSpeed(velocity2);
   stepper2.setAcceleration(1000);}
void loop()
{
   if (stepper1.distanceToGo() == 0)
   {
   pos1 = -pos1;
   stepper1.moveTo(pos1);
   }
   if (stepper2.distanceToGo() == 0)
   {   
   pos2 = -pos2;
   stepper2.moveTo(pos2);
   }
    stepper1.run();
stepper2.run();
}
   

alai2015 发表于 2015-7-8 13:02:52

int 跟 float不支持"^" 運算
換成下面方式試試:
#include <math.h>
...
area1=3.14*(pow((diameter1/2), 2));

凯风自北来 发表于 2015-7-8 15:19:04

alai2015 发表于 2015-7-8 13:02 static/image/common/back.gif
int 跟 float不支持"^" 運算
換成下面方式試試:
#include


多谢,问题已解决
页: [1]
查看完整版本: 求助:编程报错invalid operands of types 'float' and 'int' to binary 'operator^'