I've been working on a very simple exercise meant to show how to use header files. The program takes a user specified range of temperatures and displays a three column table of the tempuratures converted into two different forms, the functions that actually do the conversion are stored in a header file , I am programming using Pico through the terminal in OS X and compiling using g++. Here is the code for my header (convert.h):
The code for the headers cpp file. "convert.cpp"Code:#ifndef CONVERT_H #define CONVERT_H double celsius_of(int fahr); double ab_value_of(int fahr); #endif
And the code for the main program:Code:#include<iostream> #include"convert.h" using namespace std; double celsius_of(int fahr) { return (static_cast<double>(5)/9) * (fahr - 32); } double ab_value_of(int fahr) { return ((static_cast<double>(5)/9) * (fahr - 32)) + 273.15; }
I've gone over the syntax about a million times, yet when I try to compile it g++ spits out the following error:Code:#include <iostream> #include <iomanip> #include"convert.h" using namespace std; void print_prelim_message() { cout << "This program outputs a list of temperatures converted into various forms" << endl; } void print_message_echoing_input(int lower,int upper,int step) { cout << "A chart of temperatures between " << lower << " and " << upper << " in the increment of " << step << " is as follows:" << endl; } int print_table(int lower,int upper,int step) { cout << setw(10) << "Fahrenheit" << setw(10) << "Celsius" << setw(10) << "Kelvin" << endl; for (; lower <= upper; lower = lower+step) { cout << setw(10) << lower << setw(10) << celsius_of(lower) << setw(10) << ab_value_of(lower) << endl ; } } int main () { int lower = 0; int upper = 0; int step = 1; print_prelim_message(); cout << "Please enter a minimum temp." << endl; cin >> lower; cout << "Please enter a maximum temp." << endl; cin >> upper; cout << "Please enter an increment." << endl; cin >> step; print_message_echoing_input(lower, upper, step); print_table(lower, upper, step); return 0; }
/usr/bin/ld: Undefined Symbols:
celsius_of(int)
ab_value_of(int)
collect2: ld returned 1 exit status
I have no idea what's going wrong.



LinkBack URL
About LinkBacks


