0

我在 Microsoft Visual C++ 中输入了以下代码来计算和显示油耗。

#include<iostream>
using namespace std;
//Christopher Hernandez, Programmer
//global variables
int day [3]; 
int mil [3];
int gal [3];
int mpg [3];
//function prototype
void CalcAverage (int arr1[], int arr2[], int size);
//main program
int main()
{
//local variables
char month [7];

cout << "Please enter the starting month" << endl;
cin >> month;

cout << "Please enter starting day entry 1" << endl;
cin >> day [0];
cout << "entry 2" << endl;
cin >> day [2];
cout << "entry 3" << endl;
cin >> day [3];
cout << "entry 4" << endl;
cin>> day [4];

cout << "Please enter gallons entry 1" << endl;
cin >> gal [0];
cout << "entry 2" << endl;
cin >> gal [1];
cout << "entry 3" << endl;
cin >> gal [2];
cout << "entry 4" << endl;
cin >> gal [3];

cout << "Please enter miles entry 1" << endl;
cin >> mil [0];
cout << "entry 2" << endl;
cin >> mil [1];
cout << "entry 3" << endl;
cin >> mil [2];
cout << "entry 4" << endl;
cin >> mil [3];

CalcAverage (gal,mil,3);

cout << "Week of" << "\tGallons" << "\tMiles" << "\tMPG" << endl;
cout << "_ _ _ _ _ _ _" << "\t_ _ _ _ _" << "\t_ _ _ _"  << endl;
cout << month [0] <<  " " << day [0] << "\t" << gal [0] << "\t" << mil [0] << "\t" << mpg [0] <<     endl;
cout << month [1] <<  " " << day [1] << "\t" << gal [1] << "\t" << mil [1] << "\t" << mpg [1] <<     endl;
cout << month [2] <<  " " << day [2] << "\t" << gal [2] << "\t" << mil [2] << "\t" << mpg [2] <<     endl;
cout << month [3] <<  " " << day [3] << "\t" << gal [3] << "\t" << mil [3] << "\t" << mpg [3] <<     endl;

system("PAUSE");

}
//function definition
void CalcAverage (int g, int m, int size)
{
//statements
mpg [0] = mil [0] / gal [0];
mpg [1] = mil [1] / gal [1];
mpg [2] = mil [2] / gal [2];
mpg [3] = mil [3] / gal [3];

}

不用说我没有得到想要的输出。相反,我收到以下错误

1>c:\users\computer\documents\visual studio 2010\projects\gasmileage\gasmileage\gasmileage.cpp    (66): warning C4789: destination of memory copy is too small

1>gasmileage.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification

1>gasmileage.obj : error LNK2019: unresolved external symbol "void __cdecl CalcAverage(int * const,int * const,int)" (?CalcAverage@@YAXQAH0H@Z) referenced in function _main

1>C:\Users\COMPUTER\Documents\Visual Studio 2010\Projects\GasMileage\Debug\GasMileage.exe : fatal error LNK1120: 1 unresolved externals

我的代码有什么问题?为什么我会收到这些错误?

*我还应该注意,我将增量链接设置为“关闭”,因为当我打开它时,我无法运行程序而不会收到我的 Microsoft Visual C++ 2010 已过期的消息(此消息也迫使我中止该程序)

4

1 回答 1

0

因为你的函数原型是:

void CalcAverage (int arr1[], int arr2[], int size);

但实际的函数定义是:

void CalcAverage (int g, int m, int size)
于 2013-10-24T00:32:16.620 回答