“函数调用缺少参数列表”?

时间:2016-03-09 02:54:33

标签: c++ visual-studio visual-c++ visual-studio-2015

#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES       //needed to include the math constants
#include <math.h>
#include <string>               //needed to include texts
using namespace std;

double Volume(double Length, double Width, double Height)
{
    double volume;
    volume = Length*Width*Height; 
    return volume;
}

double Area(double Length, double Width, double Height)
{
    double area;
    area = 2 * Width*Length + 2 * Length*Height + 2 * Height*Width; 
    return area;
}

void DisplayData(double Length, double Width, double Height, double volume, double area)
{
    cout << "For the width " << Width << ", the length " << Length << " and the Height " << Height << "; the volume of the box is " << volume << " and the surface area is " << area << ".";
}

int main()
{
    double Length, Width, Height;

    cout << "Welcome! This program will calculate the volume and surface area of a box. All this program needs is you to input the length, width and height of the box." << endl;
    cout << "Please note that all meausurments are in meters." << endl;
    cout << "Please insert a value for the length: " << endl;
    cin >> Length;
    cout << "Please insert a value for the width: " << endl;
    cin >> Width;
    cout << "Please insert a value for the height: " << endl;
    cin >> Height;
    cout << endl;

    Volume;
    Area;
    DisplayData;

    return 0;
}//end main

我正在编写一个带有函数的程序,但它在标题中给出了错误。我究竟如何调用函数?我真的不明白那一部分。你刚刚写了这个函数的名字还是还有其他的东西?

2 个答案:

答案 0 :(得分:0)

我想你应该调用这样的函数

Volume;
Area;
DisplayData;

而不是三个毫无意义的陈述

{{1}}

答案 1 :(得分:0)

函数名称和变量名称相互冲突。编译器将volume变量视为函数并在其后查找参数。

 double volume;

将其更改为

 double dVolume;
 dVolume = Length*Width*Height; 
 return dVolume;

area也进行类似的更改。