C++ 错误:无法转换‘;浮动’;至‘;浮动*’;争论

C++ 错误:无法转换‘;浮动’;至‘;浮动*’;争论,c++,arrays,function,C++,Arrays,Function,我的目标是将数组传递给函数,但我得到以下错误: error: cannot convert ‘float’ to ‘float*’ for argument ‘9’ to ‘void calc_fun(float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, int)’ calc_fun(rate, hrs_worked, gross, overtime, state_tax,fed_

我的目标是将数组传递给函数,但我得到以下错误:

error: cannot convert ‘float’ to ‘float*’ for argument ‘9’ to ‘void calc_fun(float*, float*, float*, float*, float*, float*, float*, float*, float*, float*, int)’ calc_fun(rate, hrs_worked, gross, overtime, state_tax,fed_tax, uni_fee, net, total_gross, avg_gross, SIZE); 任何帮助都将不胜感激,谢谢

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

const float OVERTIME_R = 1.5,
             STATE_TAX = 0.06,
             FED_TAX = 0.12,
             UNION_FEE = 0.02;

const int SIZE = 10;

typedef string INFO;

void input_fun(INFO[], INFO[], INFO[], INFO[], float[], float[], const int);
void calc_fun(float[], float[], float[], float[], float[], float[], float[], float[], float[], float[], const int);

int main()
{
    INFO f_name[SIZE],
         m_name[SIZE],
         l_name[SIZE],
         ID[SIZE];

    float rate[SIZE],
          hrs_worked[SIZE],
          gross[SIZE],
          overtime[SIZE],
          state_tax[SIZE],
          fed_tax[SIZE],
          uni_fee[SIZE],
          net[SIZE],
          total_gross = 0,
          avg_gross = 0;

    input_fun(f_name, m_name, l_name, ID, rate, hrs_worked, SIZE);
    calc_fun(rate, hrs_worked, gross, overtime, state_tax,fed_tax, uni_fee, net, total_gross, avg_gross, SIZE);

    return 0;
}

void input_fun(INFO first[], INFO mid[], INFO last[], INFO id[], float payrate[], float hrs[], const int S)
{

    for(int i = 0; i < S; i++)
    {
        cout << "Enter first name of employee    "<<i+1<<" : " << endl;
        cin >> first[i];

        cout << "Enter middle name of employee   "<<i+1<<" : " << endl;
        cin >> mid[i];

        cout << "Enter last name of employee     "<<i+1<<" : " << endl;
        cin >> last[i];

        cout << "Enter the ID of employee        "<<i+1<<" : " << endl;
        cin >> id[i];

        cout << "Pay rate of employee " << i+1 << ": " << endl;
        cin >> payrate[i];

        if(payrate[i] < 0 || payrate[i] > 50)
        {
            while(payrate[i] < 0 || payrate[i] > 50)
            {
                cout << "Must be between 0 and 50: " << endl;
                cin >> payrate[i];
            }
        }

        cout << "Hours of work by employee " << i+1 << ": " << endl;
        cin >> hrs[i];

        if(hrs[i] < 0 || hrs[i] > 60)
        {
            while(hrs[i] < 0 || hrs[i] > 60)
            {
                cout << "Must be between 0 and 60: " << endl;
                cin >> hrs[i];
            }
        }

    }

}

void calc_fun(float rate[], float hrs[], float gross[], float overt[], float st_tx[], float fed_tx[], float uni_fee[],
        float net[], float tgross, float agross, const int S){
    for (int i = 0; i < S; i++) {
        if (hrs[i] > 40) {
            overt[i] = (hrs[i] - 40.0) * rate[i] * OVERTIME_R;
        }

        gross[i] = (rate[i] * hrs[i]) + overt[i];

        st_tx[i] = gross[i] * STATE_TAX;
        fed_tx[i] = gross[i] * FED_TAX;
        uni_fee[i] = gross[i] * UNION_FEE;
        net[i] = gross[i] - (st_tx[i] + fed_tx[i] + uni_fee[i]);

        tgross += gross[i];
        agross = tgross / S;

    }
}
#包括
#包括
#包括
#包括
使用名称空间std;
常数浮动超时时间=1.5,
州税=0.06,
联邦税=0.12,
工会费=0.02;
常数int SIZE=10;
typedef字符串信息;
无效输入(信息[],信息[],信息[],信息[],信息[],浮点[],浮点[],常量int);
无效计算(浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],浮点[],常量整数);
int main()
{
信息f_名称[大小],
m_名称[尺寸],
l_名称[尺寸],
ID[大小];
浮动利率[大小],
工作时数[尺寸],
总[尺寸],
加班[人数],
州税[规模],
美联储税[规模],
统一费用[大小],
净[尺寸],
总金额=0,
平均毛额=0;
输入乐趣(f_名称、m_名称、l_名称、ID、费率、工时、大小);
计算费用(费率、工作小时数、总额、加班费、州税、联邦税、统一费用、净额、总额、平均总额、规模);
返回0;
}
无效输入乐趣(信息优先[]、信息中间[]、信息最后[]、信息id[]、浮动工资率[]、浮动小时数[]、常量整数S)
{
对于(int i=0;i
您已将
total\u gross
声明为
float
。它不是数组,也不是指针


您将
total\u gross
作为声明为指针的参数传递。类型不匹配。

编译器发出的错误消息很清楚。第9个参数应该是
float*
。您将
float
@RSahu传递,但为什么应该是
float*
。它与其他参数有什么不同在函数的9个参数中,你可能想考虑把你的数据聚合成一个结构,并有一个结构的数组。它的好处是巨大的。@ USER481301我希望我能,但是教授不允许它用于这个任务,因为我们还没有检查过结构。@ DavidGordeladze——看看你的函数。声明。编写它是为了使第9个参数为
float*
。另外,指定
float[]
作为参数与指定
float*
没有什么不同。
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

using namespace std;

const float OVERTIME_R = 1.5,
             STATE_TAX = 0.06,
             FED_TAX = 0.12,
             UNION_FEE = 0.02;

const int SIZE = 10;

typedef string INFO;

void input_fun(INFO[], INFO[], INFO[], INFO[], float[], float[], const int);
void calc_fun(float[], float[], float[], float[], float[], float[], float[], float[], float[], float[], const int);

int main()
{
    INFO f_name[SIZE],
         m_name[SIZE],
         l_name[SIZE],
         ID[SIZE];

    float rate[SIZE],
          hrs_worked[SIZE],
          gross[SIZE],
          overtime[SIZE],
          state_tax[SIZE],
          fed_tax[SIZE],
          uni_fee[SIZE],
          net[SIZE],
          total_gross = 0,
          avg_gross = 0;

    input_fun(f_name, m_name, l_name, ID, rate, hrs_worked, SIZE);
    calc_fun(rate, hrs_worked, gross, overtime, state_tax,fed_tax, uni_fee, net, total_gross, avg_gross, SIZE);

    return 0;
}

void input_fun(INFO first[], INFO mid[], INFO last[], INFO id[], float payrate[], float hrs[], const int S)
{

    for(int i = 0; i < S; i++)
    {
        cout << "Enter first name of employee    "<<i+1<<" : " << endl;
        cin >> first[i];

        cout << "Enter middle name of employee   "<<i+1<<" : " << endl;
        cin >> mid[i];

        cout << "Enter last name of employee     "<<i+1<<" : " << endl;
        cin >> last[i];

        cout << "Enter the ID of employee        "<<i+1<<" : " << endl;
        cin >> id[i];

        cout << "Pay rate of employee " << i+1 << ": " << endl;
        cin >> payrate[i];

        if(payrate[i] < 0 || payrate[i] > 50)
        {
            while(payrate[i] < 0 || payrate[i] > 50)
            {
                cout << "Must be between 0 and 50: " << endl;
                cin >> payrate[i];
            }
        }

        cout << "Hours of work by employee " << i+1 << ": " << endl;
        cin >> hrs[i];

        if(hrs[i] < 0 || hrs[i] > 60)
        {
            while(hrs[i] < 0 || hrs[i] > 60)
            {
                cout << "Must be between 0 and 60: " << endl;
                cin >> hrs[i];
            }
        }

    }

}

void calc_fun(float rate[], float hrs[], float gross[], float overt[], float st_tx[], float fed_tx[], float uni_fee[],
        float net[], float tgross, float agross, const int S){
    for (int i = 0; i < S; i++) {
        if (hrs[i] > 40) {
            overt[i] = (hrs[i] - 40.0) * rate[i] * OVERTIME_R;
        }

        gross[i] = (rate[i] * hrs[i]) + overt[i];

        st_tx[i] = gross[i] * STATE_TAX;
        fed_tx[i] = gross[i] * FED_TAX;
        uni_fee[i] = gross[i] * UNION_FEE;
        net[i] = gross[i] - (st_tx[i] + fed_tx[i] + uni_fee[i]);

        tgross += gross[i];
        agross = tgross / S;

    }
}
void calc_fun(float[], float[], float[], float[], float[], float[], float[], float[], float[], float[], const int);
// scroll right                                                                                ^^^^^^^
float /* snip */
      total_gross = 0,
calc_fun(rate, hrs_worked, gross, overtime, state_tax,fed_tax, uni_fee, net, total_gross, avg_gross, SIZE);
// scroll right                                                              ^^^^^^^^^^^