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

am1*_*212 1 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;
}
Run Code Online (Sandbox Code Playgroud)

bil*_*llz 6

我相信你的代码中有拼写错误

你声明了

void iceCreamDivision(int number, double totalWeight);
Run Code Online (Sandbox Code Playgroud)

但你定义了

void iceCreamDivison(int number, double totalWeight)
Run Code Online (Sandbox Code Playgroud)

注意之间的差异DivisionDivison.看到学习C++也可以帮助你学习英语.