/* Cody Cook 2023/04/13 CS-210 Project 3 */ #include // use cout and cin #include // for use in menuItems #include "Items.h" using namespace std; void menu() { unsigned int input = 0; Items Items; string search; // create a vector of the menu items vector menuItems = { "Check the purchase frequency of an item.", // input 1 "Display the purchase frequency of all items.", // input 2 "Display the purchase frequency of all items in a histogram.", // input 3 "Exit." // input 4 }; // loop until the user enters the exit input while (input != 4) { cout << "Corner Grocer: Inventory Menu\n\n"; for (unsigned int i = 0; i < menuItems.size(); i++) { cout << c_red << i + 1 << c_normal << ". " << menuItems[i] << endl; } cout << endl << "Enter your choice: " << c_red; cin >> input; cout << c_normal; // if the user enters a non-integer if (cin.fail()) { cin.clear(); // clear the error flag cin.ignore(1000, '\n'); // ignore the rest of the input input = 0; // set the input to 0 } cout << endl; switch (input) { case 1: cout << "Enter an item you wish to check the purchase frequency: "; cout << c_red; cin >> search; cout << c_normal; Items.GetInventory(search); break; case 2: Items.PrintInventory(1); break; case 3: Items.PrintInventory(2); break; case 4: cout << "Goodbye!" << endl; break; default: cerr << "Invalid input. Please try again." << endl; break; } cout << endl; system("pause"); cout << endl; } } int main() { // call the menu function menu(); // return successful return 0; }