我正在尝试编写一个程序来计算球在各个时间点的高度,但是每当尝试编译时,都会收到错误LNK2019。而且,它总是告诉我我的双打被转换为整数,但是我不知道为什么。


  1> ------开始构建:项目:Parabola,配置:调试Win32 ------
  1> 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:'argument':从'double'转换为'int',可能丢失数据
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(21):警告C4244:'argument':从'double'转换为'int',可能丢失数据
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(22):警告C4244:'argument':从'double'转换为'int',可能丢失数据
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(23):警告C4244:'argument':从'double'转换为'int',可能丢失数据
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(24):警告C4244:'argument':从'double'转换为'int',可能丢失数据
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ parabola.cpp(25):警告C4244:'argument':从'double'转换为'int',可能丢失数据
  1> Functions.cpp
  1> c:\ users \ oliver \ documents \ Visual Studio 2015 \ projects \ parabola \ parabola \ constants.h(2):警告C4244:'正在初始化':从'double'转换为'int',可能丢失数据
  1>正在生成代码...
  1> Parabola.obj:错误LNK2019:函数_main中引用的未解析的外部符号“ double __cdecl ballHeight(int,double)”(?ballHeight @@ YANHN @ Z)
  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;
}


功能.h

#pragma once
#include "stdafx.h"
int main();
double getHeight();
double ballHeight(int seconds, double bHeight);
void tryAgain();


常量

#pragma once
const int gConstant = 9.8;

最佳答案

double ballHeight(double bHeight, int seconds)




double ballHeight(int seconds, double bHeight)


签名是不同的。

07-25 20:38