ERROR"无法将'浮动'转换为'浮动......'......"

0 c++ floating-point compiler-errors function

这里可能还有其他一些格式错误,我需要修复等等,但我需要帮助的是如何处理以下内容:

Lab8pt1.cpp:在函数'float Salary(float,float)'中:
Lab8pt1.cpp:48:错误:赋值函数'float Salary(float,float)'
Lab8pt1.cpp:48:错误:无法将'float'转换为'float()(float,float)'赋值
给Lab8pt1.cpp:50:错误:赋值函数'float Salary(float,float)'
Lab8pt1.cpp:50:错误:无法将'double'转换为'float() (float,float)'赋值
Lab8pt1.cpp:51:错误:无法将'float(*)(float,float)'转换为'float'作为回报

我知道这是指我的薪水功能,但我不确定浮动的问题是什么.这应该是一个简单的实验室作业,教我们如何使用函数(我们只需编写函数的代码,其余的给我们).

请帮忙!提前致谢!

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

using namespace std ;

void Header(void) ;            
float Salary(float Hours, float Pay_Rate);  
void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name);  
void Read(float &hour, float &Pay_R,string &name) ;
bool Verify(float Hours, float Pay_Rate);  

int main ( void )
{
    float   Pay_Rate, Hours, Sal, Tax;
    const float  Tax_Rate= (float)0.09 ;
    string name;

    Header();
    for(int i = 0 ; i < 3 ; i++){
         Read(Hours,Pay_Rate,name);
         Sal = Salary(Hours,Pay_Rate);
         Print_it(Hours,Pay_Rate,Sal, Tax_Rate,name);    
    }
    cout<<"\n\n\n**********\t End of report \t*****\n\n\n\n";
    return 0 ;
}

void Header( void )
{
     string name;
     cout << "Welcome, " << name << ", to the Salary Calculator: a program that will calculate your salary.";
     return;
} 

float Salary(float Hours, float Pay_Rate)
{
     if( Hours <= 40 )
         Salary = Hours * Pay_Rate;
     else if( Hours > 40)
         Salary = Hours * (Pay_Rate * 1.5);
     return(Salary);
}

void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name)
{
     cout << fixed << setprecision(2);
     cout << "Name: " << left << setw(15) << Name << endl;
     cout << "Hours worked: " << left << setw(15) << Hours << endl;
     cout << "Pay rate: " << left << setw(15) << Pay_Rate << endl;
     cout << "Tax rate: " << left << setw(15) << Tax_Rate << endl;
     cout << "Salary: " << left << setw(15) << Sal << endl;
     return;
}

void Read(float &hour, float &Pay_R,string &name) 
{
     cout << "Please enter your name: ";
     getline(cin, name);
     cout << "Please enter number of hours worked: ";
     cin >> hour;
     cout << "Please enter your pay rate: ";
     cin >> Pay_R;
     return;
}

bool Verify(float Hours, float Pay_Rate)
{
     if( Hours < 0 || Hours > 60 || Pay_Rate < 0 || Pay_Rate > 500)
         return false;
     else
         return true;
}  
Run Code Online (Sandbox Code Playgroud)

tas*_*oor 5

Salary = Hours * Pay_Rate;
Run Code Online (Sandbox Code Playgroud)

Salary是函数名称.您无法为其指定浮点值.您需要声明一个float变量并返回该变量.

float sal;

sal = Hours * Pay_Rate;

return sal;
Run Code Online (Sandbox Code Playgroud)

实际上你不需要这个变量.您可以直接在if-else块内返回.

if( Hours <= 40 )
    return Hours * Pay_Rate;
Run Code Online (Sandbox Code Playgroud)

请注意,方法和变量名称应以小写字母开头,类名称应以大写字母开头.这是广泛使用的惯例.