Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // inventorySystem.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include "InventoryItem.cpp"
- //function that takes in an id and a price and checks if they are valid
- void invalidInput(std::string invalidItem);
- void printItems(InventoryItem itmes[],int itemCount);
- int getId();
- float getPrice();
- int main()
- {
- const int ITEM_COUNT = 5;
- InventoryItem items[ITEM_COUNT];
- //instructions for id and price entry
- //id and price entry
- for (int i = 0; i < ITEM_COUNT; i++) {
- int id = getId();
- float price = getPrice();
- items[i] = InventoryItem(id, price);
- std::cout << "----------------------\n\n";
- }
- printItems(items,ITEM_COUNT);
- }
- float getPrice() {
- float price;
- std::cout << "Enter a price: ";
- std::cin >> price;
- while (price <= 0) {
- std::cout << "Error: The price that you entered was invalid";
- std::cout << "\nEnter a price: ";
- std::cin >> price;
- }
- return price;
- }
- int getId() {
- int id;
- std::cout << "Enter a ID: ";
- std::cin >> id;
- while (id <= 0) {
- std::cout << "Error: The id that you entered was invalid";
- std::cout << "\nEnter a id: ";
- std::cin >> id;
- }
- return id;
- }
- void printItems(InventoryItem items[], int itemCount) {
- for (int i = 0; i < itemCount; i++) {
- std::cout << (i + 1) << ") id: " << items[i].getId() << " price: " << items[i].getPrice() << "\n";
- }
- }
- void invalidInput(std::string invalidItem) {
- std::cout << "Error: The " << invalidItem << " that you have entered is invalid, please try again.\n";
- }
- // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
- // Debug program: F5 or Debug > Start Debugging menu
- // Tips for Getting Started:
- // 1. Use the Solution Explorer window to add/manage files
- // 2. Use the Team Explorer window to connect to source control
- // 3. Use the Output window to see build output and other messages
- // 4. Use the Error List window to view errors
- // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
- // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement