I'm trying to write a program to calculate the height of a ball at various points in time, but whenever I try to compile I get error LNK2019. Also, it keeps telling me my doubles get converted to ints but I don't know why.
1>------ Build started: Project: Parabola, Configuration: Debug Win32 ------ 1> Parabola.cpp 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\constants.h(2): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(20): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(21): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(22): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(23): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(24): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\parabola.cpp(25): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data 1> Functions.cpp 1>c:\users\oliver\documents\visual studio 2015\projects\parabola\parabola\constants.h(2): warning C4244: 'initializing': conversion from 'double' to 'int', possible loss of data 1> Generating Code... 1>Parabola.obj : error LNK2019: unresolved external symbol "double __cdecl ballHeight(int,double)" (?ballHeight@@YANHN@Z) referenced in function _main 1>C:\Users\OLIVER\Documents\Visual Studio 2015\Projects\Parabola\Debug\Parabola.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Here are all the files.
Main
#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;
}
Functions
#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;