【问题标题】:"Function call missing argument list"?“函数调用缺少参数列表”?
【发布时间】:2016-03-09 02:54:33
【问题描述】:
#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

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

【问题讨论】:

  • GCC didn't give me any error,但是你想调用函数而不是放置只包含函数名的无意义语句吗?
  • 本周迄今为止最好的巨魔。格式良好的问题。有意义的函数名称,明确命名的参数。然后是妙语。太棒了。
  • @MikeCat 你是什么意思?不是很懂
  • @SamVarshavchik D:你是什么意思?我只是有很多问题,我不明白很多东西。

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


【解决方案1】:

我猜你应该这样调用函数

double volume = Volume(Length, Width, Height);
double area = Area(Length, Width, Height);
DisplayData(Length, Width, Height, volume, area);

而不是三个无意义的陈述

Volume;
Area;
DisplayData;

【讨论】:

  • 好的,我知道了。您想在调用变量时声明内容。
  • @BobSmith 你什么意思?
  • @BobSmith 想像一个类似于手持计算器的功能。要添加两个数字,您不仅要按“+”键并看着计算器等待答案。这基本上就是您在原始代码中所做的。您还必须输入要添加的两个数字。这两个数字是参数。同样的事情——Volume 需要参数才能做某事。
  • @PaulMcKenzie 谢谢。现在更有意义了。我会在编写函数时保留它。
【解决方案2】:

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

 double volume;

改成

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

对area 也进行类似的更改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多