Advertisement
cperryoh

Main

Mar 12th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // inventorySystem.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3. #include <iostream>
  4. #include "InventoryItem.cpp"
  5. //function that takes in an id and a price and checks if they are valid
  6. void invalidInput(std::string invalidItem);
  7. void printItems(InventoryItem itmes[]);
  8. int getId();
  9. float getPrice();
  10. int main()
  11. {
  12.     const int ITEM_COUNT = 5;
  13.     InventoryItem items[ITEM_COUNT];
  14.  
  15.     //instructions for id and price entry
  16.     //id and price entry
  17.     for (int i = 0; i < ITEM_COUNT; i++) {
  18.         int id = getId();
  19.         float price = getPrice();
  20.         items[i] = InventoryItem(id, price);
  21.         std::cout << "----------------------\n\n";
  22.     }
  23.     printItems(items);
  24. }
  25. float getPrice() {
  26.     float price;
  27.     std::cout << "Enter a price: ";
  28.     std::cin >> price;
  29.     while (price <= 0) {
  30.         std::cout << "Error: The price that you entered was invalid";
  31.         std::cout << "\nEnter a price: ";
  32.         std::cin >> price;
  33.     }
  34.     return price;
  35. }
  36.  
  37. int getId() {
  38.     int id;
  39.  
  40.     std::cout << "Enter a ID: ";
  41.     std::cin >> id;
  42.     while (id <= 0) {
  43.         std::cout << "Error: The id that you entered was invalid";
  44.         std::cout << "\nEnter a id: ";
  45.         std::cin >> id;
  46.     }
  47.     return id;
  48. }
  49. void printItems(InventoryItem items[]) {
  50.     for (int i = 0; i < (sizeof(items) / sizeof(items)); i++) {
  51.         std::cout << (i + 1) << ") id: " << items[i].getId() << " price: " << items[i].getPrice() << "\n";
  52.     }
  53. }
  54. void invalidInput(std::string invalidItem) {
  55.     std::cout << "Error: The " << invalidItem << " that you have entered is invalid, please try again.\n";
  56. }
  57. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  58. // Debug program: F5 or Debug > Start Debugging menu
  59. // Tips for Getting Started:
  60. // 1. Use the Solution Explorer window to add/manage files
  61. // 2. Use the Team Explorer window to connect to source control
  62. // 3. Use the Output window to see build output and other messages
  63. // 4. Use the Error List window to view errors
  64. // 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
  65. // 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