【发布时间】:2011-02-23 02:59:09
【问题描述】:
首先这是我关于stackoverflow的第一个问题。我正在尝试完成家庭作业,但我不知道我做错了什么。
当我第二次尝试运行一个函数时,我收到一个错误“没有从 'int' 到 'int (__cdecl *)(float,float)' 的转换”。该函数应该返回 0、-1 或 +1,并在 if/else 语句中使用。
这是我指的代码块...
#include <iostream>
using namespace std;
////this function returns a -1 if the left pan has a weight more than the right, a 0 if the weights of the two pans are equal, and a +1 if the right pan has a greater weight than the left
int weigh(float leftpan, float rightpan)
{
//compare the pan weights, return value
}
float findOddRock(float r1, float r2, float r3, float r4, float r5, float r6, float r7)
{
//first weigh
float first_leftpan = r1 + r2;
float first_rightpan = r3 + r4;
weigh(first_leftpan, first_rightpan);
if(weigh == 0){
cout << "this program is working so far";
float second_leftpan = r5; //this brings up an error for some reason
float second_rightpan = r6;
weigh(second_leftpan, second_rightpan);
//here's where I get the error, no conversion from 'int' to 'int (__cdecl *)(float,float)'
if(weigh == 0){ //be careful here, changed from second_weigh to weigh
float third_leftpan = r5;
float third_rightpan = r7;
weigh(third_leftpan, third_rightpan);
}
//
int main()
{
//find the light rock
findOddRock(2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0);
}
【问题讨论】:
标签: c++