#include <iostream>
#include <string>
#include <iomanip>
#include "mainmenu.h"
using namespace std;
string bookTitle[20] = {0};
string isbn[20] = {0};
string author[20] = {0};
string publisher[20] = {0};
string dateAdded[20] = {0};
int qtyOnHand[20] = {0};
double wholesale[20] = {0.0};
double retail[20] = {0.0};
void main()
{
// Declarations for function
int choice;
// Constants for menu choices
const int Cashier_Module = 1,
Inventory_Database_Module = 2,
Report_Module = 3,
Exit = 4;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Main Menu\n\n";
cout << " 1. Cashier Module\n";
cout << " 2. Inventory Database Module\n";
cout << " 3. Book Information Module\n";
cout << " 4. Report Module\n";
cout << " 5. Exit\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
// Choice validation
switch (choice)
{
case 1: cashier();
break;
case 2: invMenu();
break;
case 3: bookInfo(isbn, bookTitle, author, publisher, dateAdded, qtyOnHand, wholesale, retail);
break;
case 4: reports();
break;
case 5: cout << " You have chosen to end the program.\n";
break;
default: cout << " Please enter a number in the range of 1-5.\n";
}
cout << endl;
} while (choice != 5);
cout << "\n";
}
void cashier()
{
// Declarations for function
string date;
string isbn;
string title;
int quantity, answer;
float price_of_book, subtotal, tax, total, percent_of_tax;
do
{
// Read input
cout << " Please fill in the information below:\n\n";
cout << " Please enter the date in the form (MM/DD/YYYY): ";
cin >> date;
cout << " Enter the ISBN of the book in the form (X-XXX-XXXXX-X): ";
cin >> isbn;
cin.ignore(); // Skips to the next character so I can enter the title
// *Need to use this before a getline so i can enter the next statement*
cout << " Enter the title of the book: ";
getline(cin, title); // Allows me to enter a name with spaces
cout << " Enter the number of books: ";
cin >> quantity;
cout << " Enter the price of the book: ";
cin >> price_of_book;
cout << " Enter the percent of tax: ";
cin >> percent_of_tax;
cout << "\n\n\n";
// Calculations
subtotal = quantity * price_of_book;
tax = subtotal * percent_of_tax;
total = subtotal + tax;
// Display Results
cout << setprecision(2) << fixed << showpoint;
cout << " Serendipity Book Sellers\n\n\n";
cout << " Date: " << date << endl;
cout << "\n";
cout << " Qty ISBN Title Price Total\n";
cout << " ________________________________________________________________\n";
cout << setw(3) << quantity << setw(15) << isbn << setw(13) << title << setw(15) << "$ " << price_of_book <<
setw(9) << "$ " << subtotal << endl;
cout << "\n\n\n";
cout << " Subtotal $ " << subtotal << endl;
cout << " Tax $ " << tax << endl;
cout << " Total $ " << total << endl;
cout << "\n\n";
cout << "Would you like to make another transaction?" << endl;
cout << "(1 = Yes & 2 = No): ";
cin >> answer;
cout << "\n";
} while(answer == 1);
while (answer == 2)
{
cout << "Thank You for Shopping at Serendipity!\n\n";
break;
}
}
void invMenu()
{
// Declarations for function
int choice;
// Constants for menu choices
const int Look_up_a_book = 1,
Add_a_book = 2,
Edit_a_book_record = 3,
Delete_a_book = 4,
Return_to_main_menu = 5;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Inventory Database\n\n";
cout << " 1. Look Up a Book\n";
cout << " 2. Add a Book\n";
cout << " 3. Edit a Book's Record\n";
cout << " 4. Delete a Book\n";
cout << " 5. Return to the Main Menu\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
// Choice validation
switch (choice)
{
case 1: lookUpBook();
break;
case 2: addBook();
break;
case 3: editBook();
break;
case 4: deleteBook();
break;
case 5: cout << " You have chosen to return to the Main Menu.\n";
break;
default: cout << " Please enter a number in the range 1-5.\n";
}
cout << endl;
} while (choice != 5);
cout << "\n";
}
void bookInfo(string bookTitle[], string isbn[], string author[], string publisher[], string dateAdded[], int qtyOnHand[], double wholesale[], double retail[])
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Book Information\n\n\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\n";
}
void reports()
{
// Declarations for function
int choice;
// Constants for program
const int Inventory_listing = 1,
Inventory_wholesale = 2,
Inventory_retail = 3,
Listing_quantity = 4,
Listing_cost = 5,
Listing_age = 6,
Main_menu = 7;
do
{
// Read input
cout << " Serendipity Booksellers\n";
cout << " Reports\n\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 Main Menu\n\n";
cout << " Enter Your Choice: ";
cin >> choice;
cout << "\n";
switch (choice)
{
case 1: repListing();
break;
case 2: repWholesale();
break;
case 3: repRetail();
break;
case 4: repQty();
break;
case 5: repCost();
break;
case 6: repAge();
break;
case 7: cout << " You have chosen to return to the Main Menu.\n";
break;
default: cout << " Please enter a number in the range 1-7.\n";
}
cout << endl;
} while (choice != 7);
cout << "\n";
}
// ************************************
// Inventory Database Stub Functions *
// ************************************
void lookUpBook()
{
cout << " You selected Look Up Book.\n";
}
void addBook()
{
while (bookTitle[] == 0)
{
cout << "Please enter the information for the following:\n\n";
cout << "Enter the title of the book: ";
getline(cin, bookTitle[]);
cout << "Enter the ISBN of the book in the form (X-XXX-XXXXX-X): ";
cin >> isbn[];
cout << "Enter the name of the author: ";
cin >> author[];
cout << "Enter the name of the publisher: ";
getline(cin, publisher[]);
cout << "Enter the date added, in the form (MM/DD/YYYY): ";
cin >> dateAdded[];
cout << "Enter the quantity of the book being added: ";
cin >> qtyOnHand[];
cout << "Enter the wholesale cost of the book: ";
cin >> wholesale[];
cout << "Enter the retail price of the book: ";
cin >> retail[];
}
if (bookTitle[] == 20)
{
cout << "No more books may be added to the inventory!";
break;
}
}
void editBook()
{
cout << " You selected Edit Book.\n";
}
void deleteBook()
{
cout << " You selected Delete Book.\n";
}
// ************************
// Report Stub Functions *
// ************************
void repListing()
{
cout << " You selected Inventory Listing.\n";
}
void repWholesale()
{
cout << " You selected Inventory Wholesale Value.\n";
}
void repRetail()
{
cout << " You selected Inventory Retail Value.\n";
}
void repQty()
{
cout << " You selected Listing By Quantity.\n";
}
void repCost()
{
cout << " You selected Listing By Cost.\n";
}
void repAge()
{
cout << " You selected Listing By Age.\n";
}
---------------------------------------------------------------------------------------------------------------
Hello everyone,
The problem I am having is in the "addBook" function, I'm trying to make sure the string is empty, and if it is I will ask the user to enter the information into each array.
I don't think i'm entering the information into the array properly either.
Can anyone help me on these two problems?
Lines 251-272.