Hey everyone. I'm new to the forums and to C++, and I was working on a program used to call data from a file containing various information about cars when I ran across the error:

undefined reference to (and then it proceeds to list all of my declared functions).

Here's my code:

//Ebony Lewis
//Lab Section L01
//Final Exam Program
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

void FindcarVin(int , string , string, int , int );
void ListcarBrand( string ,string ,int );
void ListcarModel(string ,string , int );
void ListcarYear ( int , string , string );
int CarleastMileage( string , string , int , int );
int CarhighestMPG ( string , string , int , float );

//This struct will hold the information for all of the cars.

struct UsedCars
{
int cars;
int vin;
string brand;
string model;
int year;
int mileage;
float MPG;
};

int main ()
{
const int NUM_CARS = 30;
int i= 0, choice;
int inVin;
//Declare a variable called CarChoice of the UsedCars type.
UsedCars CarChoice[NUM_CARS];
ifstream readFile;
readFile.open ( "UsedCars.txt");


if ( !readFile)

cout << " File not open!";

//To make sure that it reads at least once, I'll use do while until the eof is reached.
do
{
readFile >> CarChoice[i] .cars>> CarChoice[i].vin >>CarChoice[i] .brand>>CarChoice[i].model >> CarChoice[i].year;
readFile >> CarChoice[i].mileage >> CarChoice[i].MPG;
i++;
}while(readFile.eof());

//Close the file.
readFile.close ();

//Menu for program.
do{

cout << " Weclome to the Used Car Management Program!"<< endl;
cout << " Please Enter a Choice : ";
cout << " 1. Find Car by Vin # \n ";
cout << " 2. List Cars by Brand \n ";
cout << " 3. List Cars by Model\n " ;
cout << " 4. List Cars by Year \n";
cout << " 5. Find Car with Least Mileage \n";
cout << " 6. Find Car with Highest MPG (Miles Per Gallon) \n";
cout << " 7. Quit \n \n";
cin >> choice;
} while ( choice < 1 || choice > 7);
switch (choice)
{

case 1: cout << "Enter the VIN# : " ;
                cin >> inVin;
                system("Pause");
                for (int i = 0; i < 30; i++)
                {
                    FindcarVin(CarChoice[i].vin, CarChoice[i].brand, CarChoice[i].model, CarChoice[i].year, inVin);
                }
break;

case 2: cout << "Now printing all cars by brand..." << endl;
                system("Pause");
                for (int i = 0; i < 30; i++)
                {
                    ListcarBrand(CarChoice[i].brand, CarChoice[i].model, CarChoice[i].year);
                }
break;


case 3: cout << "Now printing all cars by model..." << endl;
                system("Pause");
                for (int i = 0; i < 30; i++)
                {
                    ListcarModel(CarChoice[i].model, CarChoice[i].brand, CarChoice[i].year);
                }
break;

case 4: cout << "Now printing all cars by year..." << endl;
                system("Pause");
                for (int i = 0; i < 30; i++)
                {
                    ListcarYear(CarChoice[i].year, CarChoice[i].model, CarChoice[i].brand);
                }
break;

case 5 : cout << "The following car has the least mileage: \n";
{
                system("Pause");
                int mile;
                mile = CarleastMileage(CarChoice[i].brand, CarChoice[i].model, CarChoice[i].year, CarChoice[i].mileage);
                cout << CarChoice[mile].brand << " " << CarChoice[mile].model << " " << CarChoice[mile].year << " " << CarChoice[mile].mileage << endl;
}
break;

case 6: cout << "The following car has the least mileage: \n";
{
                system("Pause");
                int milespg;
                milespg = CarhighestMPG(CarChoice[i].brand, CarChoice[i].model, CarChoice[i].year, CarChoice[i].MPG);
                cout << CarChoice[milespg].brand << " " << CarChoice[milespg].model << " " << CarChoice[milespg].year << " " << CarChoice[milespg].MPG << endl;
}
break;

case 7: break;
}

return 0 ;
}

void FindcarVin ( int vinnums[], string brandnames[], string modelnames[], int yearnums[], int specnum )
{
for ( int i = 0; i < 30; i ++ )
{
if (vinnums[i] == specnum)
cout << vinnums[i] << " " << brandnames[i] << " " << modelnames[i] << " " << yearnums [i] << endl;
}
}


void ListcarBrand ( string brandnames [], string modelnames [], int yearnums [])
{
for( int i = 0; i < 30; i++)
{
cout << brandnames[i] << " " << modelnames[i] << " " << yearnums[i] << endl;
}
}


void ListcarModel ( string modelnames [], string brandnames [], int yearnums [])
{
for ( int i = 0; i < 30 ; i ++ )
{
cout << brandnames[i] << " " << modelnames[i] << " " << yearnums[i] << endl;
}
}


void ListcarYear ( int yearnums [], string modelnames [], string brandnames [])
{
for( int i = 0; i < 30; i ++ )
{
cout << brandnames[i] << " " << modelnames[i] << " " << yearnums[i] << endl;
}
}


int CarleastMileage ( string brandnames [], string modelnames [] , int yearnums [], int mileagenums [])
{
int least = mileagenums[0]; //Declare this as the max value.
int mile;
for ( int i = 0; i < 30; i ++ )
{
if (mileagenums[i] < least)
{
least = mileagenums[i];
mile = i;
}
}
return mile;
}


int CarhighestMPG ( string brandnames [], string modelnames [], int yearnums [], float MPGnums [])
{
    float highest = MPGnums[0];
    int milespg;
for ( int i = 0; i < 30; i ++)
{
if (MPGnums[i] > highest)
{
highest = MPGnums[i];
milespg = i;
}
}
return milespg;
}

Can anyone give me a nudge in the right direction?
My code is attached as well.
Thank you!

This: void FindcarVin(int , string , string, int , int ); is not the same as this: void FindcarVin ( int vinnums[], string brandnames[], string modelnames[], int yearnums[], int specnum ) See the difference? It's always best to copy the definition's signature, both to ensure the prototype is the same and also it's useful to have the variable names even in the prototype (since this is all one will see in a header file).

Alrighty! Thank you; I'll fix it and see if we've got progress. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.