我试图编写一个程序来计算不同时间点球的高度,但每当我尝试编译时,我都会得到错误LNK2019。此外,它一直告诉我我的双打转换为整数,但我不知道为什么。
1> ------构建开始:项目:抛物线,配置:调试Win32 ------ 1 GT; Parabola.cpp 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ constants.h(2):警告C4244:'初始化':转换为' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(20):警告C4244:'参数':转换自' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(21):警告C4244:'参数':转换自' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(22):警告C4244:'参数':转换自' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(23):警告C4244:'参数':转换自' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(24):警告C4244:'参数':转换自' double'到' int',可能会丢失数据 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(25):警告C4244:'参数&#39 ;:转换自' double'到' int',可能会丢失数据 1 GT; Functions.cpp 1> c:\ users \ oliver \ documents \ visual studio 2015 \ projects \ parabola \ parabola \ constants.h(2):警告C4244:'初始化':转换为' double'到' int',可能会丢失数据 1 GT;生成代码...... 1> Parabola.obj:错误LNK2019:未解析的外部符号" double __cdecl ballHeight(int,double)" (?ballHeight @@ YANHN @ Z)在函数_main中引用 1> C:\ Users \ OLIVER \ Documents \ Visual Studio 2015 \ Projects \ Parabola \ Debug \ Parabola.exe:致命错误LNK1120:1未解析的外部 ==========构建:0成功,1个失败,0个最新,0个跳过==========
以下是所有文件。
主要
#include "stdafx.h"
#include <iostream>
#include "FUNCTIONS.h"
#include "CONSTANTS.h"
int main()
{
using namespace std;
cout << "Enter the height of a building (in metres) you wish to simulate dropping a ball off of." << endl;
double bHeight = getHeight(); //Building height is defined
ballHeight(bHeight, 0); //Calls the function ballHeight at various points in time
ballHeight(bHeight, 1);
ballHeight(bHeight, 2);
ballHeight(bHeight, 3);
ballHeight(bHeight, 4);
ballHeight(bHeight, 5);
return 0;
}
功能
#include "stdafx.h"
#include <iostream>
#include "CONSTANTS.h"
#include "FUNCTIONS.h"
double getHeight()
{
using namespace std;
double x = 0;
cin >> x;
return x;
}
double ballHeight(double bHeight, int seconds)
{
using namespace std;
double currentHeight = bHeight - gConstant * seconds * seconds / 2; //Calculates current ball height.
cout << "At " << seconds << " seconds, the ball is at height: " << currentHeight << " metres." << endl; //Returns the ball height.
return 0;
}
FUNCTIONS.h
#pragma once
#include "stdafx.h"
int main();
double getHeight();
double ballHeight(int seconds, double bHeight);
void tryAgain();
CONSTANTS.h
#pragma once
const int gConstant = 9.8;
答案 0 :(得分:1)
double ballHeight(double bHeight, int seconds)
VS
double ballHeight(int seconds, double bHeight)
签名不同。