我尝试调用的函数无法调用。虽然当我删除数据类型时它们被调用但是当我尝试放置数据类型时它不会工作。它编译但显示空白屏幕
还没有尝试过,因为这是我第一次遇到这种情况
函数一
double computeGrossPay(int hoursWorked, int perHourRate){
double grossPay = hoursWorked * perHourRate;
cout << "This is the computed Gross Pay"<<grossPay<<endl;
return grossPay;
}
int main (){
double computeGrossPay(int hoursWorked, int perHourRate);
}
没有错误但没有结果(空白 CMD)
最佳答案
double computeGrossPay(int hoursWorked, int perHourRate);
不调用该函数,它只是声明它。
你可能想要这样的东西:
int main (){
double myresult = computeGrossPay(10, 20);
// do something with myresult...
}
顺便说一句,如果函数的两个参数都是int
,则结果类型double
毫无意义。我让你找出原因作为练习。
关于无法调用 C++ 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58280841/