为什么我得到这个c++代码的错误

Why am I getting error with this c++ code?

本文关键字:c++ 代码 错误 为什么      更新时间:2023-10-16
#include <iostream>
using namespace std;
int volume(int l, int w, int h);
int main()
{
    int y, x, z;
    cout << "Enter The Length, Width And Height Respectively " << endl;
    cin >> y >> x >> z;
    volume(y, x, z);
    cout << "The Volume is " << volume();
    return 0;
}
int volume()
{
    return l*w*h;
}

我得到以下三个错误:-

错误'l'没有在作用域中声明。
错误'h'没有在作用域中声明。
错误'w'没有在作用域中声明。

请帮我纠正错误

您对volume的定义与其原型不匹配。它需要有您在函数原型中定义的三个参数l, wh

int volume (int l, int w, int h){
    return l*w*h;
}