简单C ++中的错误,但无法弄清楚原因

时间:2014-04-19 11:26:51

标签: c++

我有这样的代码,而且我有 1> test.obj:错误LNK2019:" void __cdecl iceCreamDivision(int,double)" (?iceCreamDivision @@ YAXHN @ Z)외부기호(참조위치:_main함수)에서확인하지못했습니다。 1> D:\ download \ CS161 \ Debug \ CS161.exe:致命错误LNK1120:1개의확인할수없는외부참조입니다。 对不起它是韩语,但它说有一个外部符号,错误在第一个void方法上。 这段代码直接来自教科书,我想知道为什么这不起作用。

#include <iostream>
using namespace std;

void iceCreamDivision(int number, double totalWeight);

int main()
{
    int number;
    double totalWeight;

    cout << "Enter the number of customers: ";
    cin >> number;
    cout << "Enter weight of ice cream to divide (in ounces): ";
    cin >> totalWeight;

    iceCreamDivision(number, totalWeight);

    return 0;
}

void iceCreamDivison(int number, double totalWeight)
{
    double portion;

    if (number == 0)
    {
        cout << "Cannot divide among zero customers.\n";
        return;
    }

    portion = totalWeight/number;
    cout << "Each one receives "
        << portion << " ounces of ice cream." << endl;
}

2 个答案:

答案 0 :(得分:6)

我相信您的代码中存在拼写错误

你宣布了

void iceCreamDivision(int number, double totalWeight);

但你定义了

void iceCreamDivison(int number, double totalWeight)

注意DivisionDivison之间的区别。 看到学习C ++也可以帮助你学习英语。

答案 1 :(得分:1)

您声明iceCreamDivision但使用拼写错误名称iceCreamDivison定义不同的函数。将缺少的i添加到定义中。

相关问题