错误消息:指向函数的指针

时间:2013-09-29 22:54:31

标签: visual-c++

我收到一条错误消息,指出表达式必须具有(指针指向)函数类型。我究竟做错了什么?我刚刚开始编码,我知道我很糟糕。我不明白如何获得工作距离的公式。

#include <cmath>    //headerfile
#include <iomanip>
#include <iostream>

    enter code here

using namespace std;

int main()
{
    double d;
    double t;
    double g;
    char choice ='y';



    //output numbers to console


    while (choice == 'y' || choice =='Y')
    {
        cout<<"Please input a value for the time"<< endl<<endl;
        cin>>t;

        g = 32;
        d = (g)(t*t);

        if (t<0)
            cout<<"You cannot have a negative time"<<endl<<endl;

        else


        cout<<setw(8)<<fixed<<setprecision(2)<<"\n""The distance the ball has fallen is "<<d<<" feet"<<endl<<endl;

        cout<<"Would you like to run this again? y for yes, any other key for no."<< endl<<endl;
        cin>>choice;
        cout<<endl;


    }
system ("Pause");
return 0;

}

2 个答案:

答案 0 :(得分:0)

如果(g)(t * t)应该是正常的乘法运算,那么它应该是g * t * t。

答案 1 :(得分:0)

在你的代码中,g是一个double,但你正在使用它,好像它是一个指向函数的指针(d = (g)(t*t);)。如果您真正想要的是将t*t乘以g,则会忘记*

d = (g)*(t*t);