"simple" library program

I keep getting linker errors after I run this program and I cannot figure out why. Please help.

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

// Function Prototypes
double CashierMod();
int InventoryMod();
double ReportMod();
char BookInfo();
int menu();

const int SIZE=50;
const int PRECISION=2;
const int NUM_BOOKS=10;
const double Tax = 0.06;

double Price, subTotal, totalSale;
char date;

struct Store
{
char ISBN [SIZE];
char title [SIZE];
char author [SIZE];
char publisher [SIZE];
char dateAdded [SIZE];
int onHand;
double wholeCost;
double retailCost;
};


char BookInfo()
{
Store BookInfo;

cout<<"Enter the book's ISBN number: \n";
cin.getline(BookInfo.ISBN, SIZE);
cout<<"Enter the title of the book: \n";
cin.getline(BookInfo.title, SIZE);
cout<<"Enter the author of the book: \n";
cin.getline(BookInfo.author, SIZE);
cout<<"Enter the publisher of the book: \n";
cin.getline(BookInfo.publisher,SIZE);
cout<<"Enter the date the book was added: \n";
cin.getline(BookInfo.dateAdded, SIZE);
cout<<"Enter the quantity of this book on hand: \n";
cin>>BookInfo.onHand;
cout<<"Enter the wholesale cost of the book: \n";
cin>>BookInfo.wholeCost;
cout<<"Enter the retail cost of the book: \n";
cin>>BookInfo.retailCost;

system ("pause");
return 0;

};

// The Main Module.
int main ()
{
int selection;

cout << fixed << showpoint << setprecision(2);
do
{
selection = menu();
switch(selection)
{
case 1 : CashierMod();
break;
case 2 : InventoryMod();
break;
case 3 : ReportMod();
break;
case 4 : BookInfo();
break;
case 5 : cout << "Exiting program.\n\n";
}
} while (selection != 5);
return 0;

}

// The Main Menu Module.
int menu()
{
int choice;
cout << "S & E Book Store\n";
cout << "\tMain Menu\n";
cout << "----------------\n";
cout << "1) Check Out\n";
cout << "2) Inventory\n";
cout << "3) Reports\n";
cout << "4) Book Information\n";
cout << "5) Exit Program\n";
cout << "Enter 1, 2, 3, 4, or 5: \n";
cin >> choice;
while (choice < 1 || choice > 5) // Validate input
{
cout << "Invalid Selection. Enter 1, 2, 3, 4, or 5: ";
cin >> choice;
}
return choice;


}

// The Cashier Module.
double CashierMod (double SubTotal, double Sales_Tax, double TotalSale)
{
int ISBN, Qty;
char date [SIZE];
cout << "S & E Book Store\n";
cout << "\tCash Register Menu\n";
cout << "----------------\n";
cout << "Please enter today's date: \n";
cin >> date; // Example: 10-Nov-2008.
cout << "Enter a valid ISBN: \n";
cin >> ISBN;
while (ISBN != 123)
{
cout << "Invalid selection. Enter a valid ISBN: \n";
cin >> ISBN;
}

cout << "Enter quantity for purchase: \n";
cin >> Qty;

cout << fixed << showpoint << setprecision(2);

// Calculate subtotal.

SubTotal = ISBN * Qty;
cout << "Subtotal: \n" << SubTotal;
// Calculate tax.
Sales_Tax = SubTotal * Tax;
cout << "Sales Tax: \n" << Sales_Tax;
// Calculate Total Sale.
TotalSale = SubTotal + Sales_Tax;
cout << "Total: \n" << TotalSale;


system ("Pause");
return 0;
}


// The Inventory Database Module.
int InventoryMod()
{
int choice;

while (true)
{
//Display the menu and get a choice
cout << endl;
cout << "S & E Book Store\n";
cout << "Inventory Database\n";
cout << "------------------\n";
cout << "1. Look-Up a Book\n";
cout << "2. Add a Book\n";
cout << "3. Edit a Books Record\n";
cout << "4. Delete a Book\n";
cout << "5. Return to the Main Menu\n";
cout << endl;
cout << "Enter your choice:" << endl;
cin >> choice;
switch (choice)
{
case 1: void lookUpbook();
break;
case 2: void addBook();
break;
case 3: void editBook();
break;
case 4: void deleteBook();
break;
case 5: cout << "Returning to main menu." << endl;
break;
}

//Validate and process the menu choice.
while (choice < 1 || choice > 5)
{
cout << "Please enter a number between one and five." << endl;
cin >> choice;
}
} while (choice != 5);
return 0;
}

//Add stub functions for inventory database

void lookUpBook()
{
//Get the title of the book to search for
cout << "Enter the title of the book you wish to search for. " << endl;

}


// The Report Module.
double ReportMod (double InvList, double WholeSaleValue, double RetailValue, double QtyList, double QtyCost, double AgeList)
{
int choice;

cout << "S & E Book Store\n";
cout << "\t Reports\n";
cout << "----------------\n";
cout << "1) Inventory Listing\n";
cout << "2) Inventory Wholesale Value\n";
cout << "3) Inventory Retail Value\n";
cout << "4) Listing by Quantity\n";
cout << "5) Listing by Cost\n";
cout << "6) Listing by Age\n";
cout << "7) Return to the Main Menu\n";
cin >> choice;
while (choice < 1 || choice > 7) // Validate input
{
cout << "Invalid Selection. Enter 1, 2, 3, 4, 5, 6, or 7: ";
cin >> choice;
}
return choice;

}

// The Book Info Module.
char BookInfo(int ISBN, char Title, char Author, char Publisher, char DateAdded, int QtyHand, int WholeCost, int RetailCost)
{
cout << "S & E Book Store\n";
cout << "Book Information\n";
cout << "----------------\n";
cout << "ISBN: \n";
cout << "Title: \n";
cout << "Author: \n";
cout << "Publisher: \n";
cout << "Date Added: \n";
cout << "Quantity on Hand: \n";
cout << "Wholesale Cost: \n";
cout << "Retail Price: \n";

system ("Pause");
return 0;

}
Well? What do they say?
[Linker error] undefined reference to `CashierMod()'
[Linker error] undefined reference to `ReportMod()'
Id returned 1 exit status

Sorry about the huge post. How do I paste code in the blue boxes?
In your first switch statement, you have:

1
2
3
case 1 : CashierMod();

case 3 : ReportMod();


but the you have CashierMod(double, double, double) and ReportMod (double, double, double, double, double, double)

GM
You have to go through tutorials for functions again.
Function declaration should give the skeleton. For example when u call a function if u expect to pass some values they must come in the bracket following it.
double CashierMod(); // This is your function prototype

double CashierMod (double SubTotal, double Sales_Tax, double TotalSale)
//This is ur function definition


The above two does not match.
In the function prototype u r telling the compiler that "somewhere in th e program u will find a function CashierMod and while calling that function I will not be passing any argument to it. Also u will find a argumentless definition somewhere else."

But compiler cannot find such a definition.

In C++, by function overloading concepts, CashierMod() and CashierMod (double SubTotal, double Sales_Tax, double TotalSale) are 2 different functions.


Also

double CashierMod (double SubTotal, double Sales_Tax, double TotalSale)

...function will be called only if you call CashierMod with three double arguments. Also u need to provide a similar function prototype.

I have not gone thru ur program in detail but one thing which came to my notice was:

double CashierMod (double SubTotal, double Sales_Tax, double TotalSale)

Here u have used the double SubTotal, double Sales_Tax, double TotalSale
to initialize normal variables not variables declared for holding values which u will be passing, while calling the function. etc etc
Last edited on
Topic archived. No new replies allowed.