Book Sellers program

Need some help with our source code. Can't figure out why our functions don't work. Can someone please give 2 non-CS majors a hand? Any help would be appreciated.

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


using namespace std;

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

// Global Variables
const int NUM_WIDTH = 10;
const int TITLE_WIDTH = 30;
const int ISBN_WIDTH = 20;
const int PRECISION = 2;
const int NUM_BOOKS =20;
const int STR_SIZE = 50;

char Book_Title [NUM_BOOKS][STR_SIZE];
char ISBN [NUM_BOOKS][STR_SIZE];
char Author [NUM_BOOKS][STR_SIZE];
char Publisher [NUM_BOOKS][STR_SIZE];
char DateAdded [NUM_BOOKS][STR_SIZE];

//Don't know if this goes here??? Got them off my notes from class.
int QtyHand [NUM_BOOKS];
double WholeCost [NUM_BOOKS];
double RetailCost [NUM_BOOKS];
char Date [STR_SIZE];
char isbnNumber [STR_SIZE];




// Sales tax
const double Tax = 0.06;

// Other Variables
double Price, SubTotal, TotalSale;



// The Main Module.
int main ()
{
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;

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

}




// The Cashier Module.
double CashierMod (double SubTotal, double Sales_Tax, double TotalSale)
{
int ISBN, Qty;
char Date [STR_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

int lookUpBook(int binarySearch, int bookInfo)
{
//Get the title of the book to search for
cout << "Enter the title of the book you wish to search for. " << endl;
cin >> Book_Title [NUM_BOOKS] [STR_SIZE];

//Search for the title of the book
int titleResults = binarySearch;

//If titleResults contain -1 the book was not found.
if (titleResults == -1)
cout << "That book was not found." << endl;
else
// //Otherwise titleResults contains the searched book
return bookInfo;
}


// 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;

}
Post any errors you're getting.
At first I was getting linker errors for all my functions. When I compile the program it doesn't show any errors. The main menu comes up but when I choose 1,2,3, 4 or 5 the program exits. I need to be able to a least get it to recognize the functions.
You have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// The Main Module.
int main ()
{
    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)
    {
        cout << "Invalid Selection. Enter 1, 2, 3, 4, or 5: ";
        cin >> choice;
    }
    return choice;  // <-- at this point the program exits
    // etc.
}

if you return on the main function the program will exit, to avoid this just remove that line
Last edited on
I am JEspin01's partner and I cannot get the program to work even when removing the "return choice;"

I get linker error's

[Linker error] undefined reference to 'menu()'
[Linker error] undefined reference to 'CashierMod()'
[Linker error] undefined reference to 'ReportMod()'
[Linker error] undefined reference to 'BookInfo()'
Id returned 1 exit status

any suggestions?
The problem is that in your switch control your function calls are not passing any arguments. You have defined function prototypes with no formal parameter list however your actual function implementations call for several parameters... which are not being passed. This applies to all of your switch controls. I also don't see any function prototypes for the following function calls which is going to be a problem:

1
2
3
4
5
6
7
8
9
10
11
12
13
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;
}


Return 0;
Last edited on
I see other problems, but fix those first. Also, when posting, please place yoru code between the code tags. Thanks.
Could you please provide an example of how I would go about deleting a book from an inventory?
I think you need to reconsider your programs design at this point. Those constant variables probably need to go to start with and you need to reorg your main program loop among other things. As far as deleting a book from inventory, as long as you know how many you actually have in inventory per book, when the user checks out and the CashierMod() function is called you would reduce that count by one, you're not necessarily going to delete a book (or object, you just need to keep track of how many you have. The way your program is designed is going to be a problem though. Can you use classes for this assignment?
Topic archived. No new replies allowed.