error compiling

I am working on one of my first c++ projects. I was provided with a .h file and had to write a .cpp file, but it won't compile. I keep getting the error message:

g++ -o proj1 proj1.cpp proj1.h /tmp/ccsK4pOL.o: In function menuMain()':
proj1.cpp:(.text+0x807): undefined reference todisplayBalance(float)' proj1.cpp:(.text+0x81b): undefined reference to deposit(float&)'
proj1.cpp:(.text+0x82f): undefined reference towithdraw(float&)' collect2: ld returned 1 exit status

This is the .h file which I cannot change:

#ifndef PROJ1_H
#define PROJ1_H

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

/*
Name: menuStart()
PreCondition: None
PostCondition: Returns the selected option (1, 2, or 3)
*/

int menuStart();

/*
Name: menuMain()
PreCondition: The user input has either been loaded from file or entered by user
PostCondition: Returns the selected option (1, 2, 3, 4, or 5)
*/
int menuMain();

/*
Name: displayAccountDetails
PreCondition: Relevant data (fName, lName, age, accountBalance) has been loaded/entered
PostCondition: None (void)
*/
void displayAccountDetails(string fName, string lName, int age, float accountBalance);

/*
Name: displayBalance
PreCondition: Relevant data (accountBalance) has been loaded/entered
PostCondition: None (void)
*/
void displayBalance(float accountBalance);

/*
Name: deposit
PreCondition: Variable accountBalance is passed-by-reference
PostCondition: accountBalance is permanently changed via pass-by-reference
*/
void deposit(float &accountBalance);

/*
Name: withdraw
PreCondition: Variable accountBalance is passed-by-reference
PostCondition: accountBalance is permanently changed via pass-by-reference
*/
void withdraw(float &accountBalance);

#endif

and this is my code - any help debugging would be appreciated, as I am very new to this.

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include "proj1.h"
using namespace std;



int main()
{

menuStart();

return 0;
}






// function definitions

int menuStart() //has user load txt file, enter info or exit
{
string firstName;
string lastName;
int userAge;
float balance;
int userIn;
cout << "Welcome to the UMBC ATM" << endl;
cout << "Choose from below: " << endl;
cout << "1. Load a User Profile from File" << endl;
cout << "2. Enter a new User Profile" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: " << endl;
cin >> userIn;

//make sure inupt is valid
while (userIn < 1 || userIn > 3)
{

cout << "INVALID. Please choose 1, 2, or 3." << endl;

cout << "Choose from below: " << endl;
cout << "1. Load a User Profile from File" << endl;
cout << "2. Enter a new User Profile" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: " << endl;
cin >> userIn;
return 0;
}

if (userIn == 1)
{

//read text file proj1.txt
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;

cout << "Name: " << firstName << lastName << endl;
cout << "Age: " << userAge << endl;
cout << "Balance: " << balance << endl;

profileTxt.close();
return 0;
}

if (userIn == 2)
{

//gather info
cout << "Please enter the following: " << endl;
cout << "First Name: " << endl;
cin >> firstName;
cout << "Last Name: " << endl;
cin >> lastName;
cout << "Age: " << endl;
cin >> userAge;
cout << "Initial Deposit: " << endl;
cin >> balance;
cout << balance << "deposited." << endl;

//write to text file to read later
ofstream profileTxt;
profileTxt.open("proj1.txt");
profileTxt << firstName << lastName << userAge << balance << endl;
profileTxt.close();

menuMain();
return 0;
}

else
{

//exit the program
return 0;

}
}
int menuMain() //main menu, user chooses 1-5
{
int userIn;

string firstName;
string lastName;
int userAge;
float balance;

//open user's profile info*
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;

cout << "********Please choose option from the menu******** " << endl;
cout << "1. Account Balance" << endl;
cout << "2. Deposit money" << endl;
cout << "3. Withdraw money" << endl;
cout << "4. Dislay your account details" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: " << endl;
cin >> userIn;

//make sure inupt is valid
while (userIn < 1 || userIn > 5)
{

cout << "INVALID. Please choose 1 - 5." << endl;

cout << "********Please choose option from the menu******** " << endl;
cout << "1. Account Balance" << endl;
cout << "2. Deposit money" << endl;
cout << "3. Withdraw money" << endl;
cout << "4. Dislay your account details" << endl;
cout << "5. Exit" << endl;
cout << "Enter your choice: " << endl;
cin >> userIn;
}

if (userIn == 1)
{

displayBalance(balance);

}

if (userIn == 2)
{

deposit(balance);

}

if (userIn == 3)
{

withdraw(balance);
}

if (userIn == 4)
{

displayAccountDetails(firstName, lastName, userAge, balance);

}

else
{

string save;
cout << "Would you like to save your account information?: " << endl;
cout << "yes or no" << endl;
cin >> save;

while ((save != "yes") || (save != "no"))
{

cout << "INVALID. Enter yes or no." << endl;
menuMain();
}

if (save == "yes") //save info to text file
//code to save info to text file
ofstream profileTxt;
profileTxt.open("proj1.txt");
profileTxt << firstName << lastName << userAge << balance << endl;
profileTxt.close();
cout << "Thank you for using the UMBC ATM";

return 0;
}

else
{

cout << "Thank you for using the UMBC ATM";

return 0;

}



}
profileTxt.close();
return 0;

}





void displayBalance(float& accountBalance) //displays account balance
{
string firstName;
string lastName;
int userAge;
float balance;

//open user's profile info*
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;
cout << "Account Balance: " << &balance << endl;

profileTxt.close();

menuMain();

}




void deposit(float accountBalance) //deposits into account
{
string firstName;
string lastName;
int userAge;
float balance;

//open user's profile info*
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;

float depAmount;
cout << "Please enter the amount to be deposited" << endl;
cin >> depAmount;

if (depAmount < 0)
{

cout << "Amount should be greater than 0" << endl;
profileTxt.close();
menuMain();
}

else
{

balance = balance + depAmount;
cout << depAmount << " deposited to your account";
profileTxt.close();
menuMain();

}
void withdraw(float accountBalance) //withdraws from account
{
string firstName;
string lastName;
int userAge;
float balance;

//open user's profile info*
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;

float withAmount;
cout << "Please enter the amount to be withdrawn" << endl;
cin >> withAmount;

if ((withAmount > balance) || (withAmount <0) )
{

cout << "Amount should be greater than 0 and greater than current account balance" << e\
ndl;
profileTxt.close();
menuMain();

}

else
{

balance = balance - withAmount;
cout << withAmount << " withdrawn from your account" << endl;
profileTxt.close();
menuMain();

}
void displayAccountDetails(std::string fName, std::string lName, int age, float accountBalanc\
e)
{
string firstName;
string lastName;
int userAge;
float balance;

//open user's profile info*
ifstream profileTxt;
profileTxt.open("proj1.txt");

profileTxt >> firstName >> lastName >> userAge >> balance;


cout << "First Name : " << firstName << endl;
cout << "Last Name : " << lastName << endl;
cout << "Age : " << userAge << endl;
cout << "Account Balance: " << balance << endl;

profileTxt.close();

menuMain();

}
What *.h and *.cpp files do you have and how do you compile?
In other words, do you compile and link all necessary *.cpp's?
Topic archived. No new replies allowed.