// Lab010Ex1.cpp � Calculate child tax credit with 3 functions
// Created by Man-Chi Leung on 10/27/10
#include <iostream>
usingnamespace std;
double readMiles();
double calcKm();
int main(double kilo)
{
readMiles();
calcKm();
cout<< "The distance in kilometers is: " << kilo << endl;
system("pause");
return 0;
}
double readMiles()
{
double miles=0;
cout<<"What is the distance in miles: ";
cin>> miles;
return miles;
}
double calcKm(double miles)
{
double kilo=0;
kilo=miles*1.67;
return kilo;
}
Compiler Error:
obj\Debug\main.o(.text+0x132)||In function `main':|
C:\Users\Showdon\Desktop\C++\Lab10\lab1004\main.cpp|14|undefined reference to `calcKm()'|
||=== Build finished: 1 errors, 0 warnings ===|
Line 9 declares a function prototype that doesn't take a double as parameter as opposed to function definition found in line 31 which does. End result: The body of double calcKm() is nowhere to be found.
Your code is invalid in whole. As for the error message then you did not define function double calcKm(); that is the definition double calcKm(double miles) does not corresponds to the declaration. The declaration has no any parameter.
main() doesn't know about the functions that are declared & defined after it. You have to forward declare the functions before main, which he tried to do but did incorrectly. The forward declarations should look like this:
1 2
double readMiles();
double calcKm(double miles);
As you can see, there's no information about what they do just that they exist and this is what parameters they take and return. If you put those definitions before the main function, it will now understand what they are and it will use them correctly, even though you don't define what they actually do until after main().
The less-good alternative would be to define those functions in their entirety before the main() function.