Advertisement
Garey

ilko

Oct 24th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. /*
  2. ______                                       _              _____ _ _
  3. | ___ \                                     | |            |_   _| | |
  4. | |_/ / __ ___   __ _ _ __ __ _ _ __ ___    | |__  _   _     | | | | | _____
  5. |  __/ '__/ _ \ / _` | '__/ _` | '_ ` _ \   | '_ \| | | |    | | | | |/ / _ \
  6. | |  | | | (_) | (_| | | | (_| | | | | | |  | |_) | |_| |   _| |_| |   < (_) |
  7. \_|  |_|  \___/ \__, |_|  \__,_|_| |_| |_|  |_.__/ \__, |   \___/|_|_|\_\___/
  8.                __/ |                              __/ |
  9.               |___/                              |___/                      
  10. */
  11. #include <iostream>
  12. #include <conio.h>
  13.  
  14. using namespace std;
  15.  
  16. // Enumerate all container sizes
  17. enum CONTAINER {
  18.   LARGE_CONTAINER = 50,
  19.   MEDIUM_CONTAINER = 20,
  20.   SMALL_CONTAINER = 5,
  21.   SINGLE_CONTAINER = 1
  22. };
  23.  
  24. // Enumerate all ship sizes
  25. enum SHIP {
  26.   LARGE_SHIP = 1500,
  27.   MEDIUM_SHIP = 1000,
  28.   SMALL_SHIP = 500
  29. };
  30.  
  31. void computate_boxes(SHIP ship_size) {
  32.   // Clear Screen
  33.   system("cls");
  34.  
  35.   // Declare number of boxes, number of containers and number of ships
  36.   int number_of_boxes, containers, ships;
  37.  
  38.   // Get container size relatively on ship size.
  39.   CONTAINER container_size = (ship_size == LARGE_SHIP ? LARGE_CONTAINER : ship_size == MEDIUM_SHIP ? MEDIUM_CONTAINER : ship_size == SMALL_SHIP ? SMALL_CONTAINER : SINGLE_CONTAINER);
  40.  
  41.   cout << "Enter the amount of boxes: ";
  42.   cin >> number_of_boxes;
  43.  
  44.   // Validate Input
  45.   !cin || number_of_boxes < 500 ? "Error: Input over 500 boxes, please!\n" : "";
  46.  
  47.   // Calculate ships and containers with the number of boxes
  48.   ships = number_of_boxes / ship_size;
  49.   containers = number_of_boxes / container_size;
  50.  
  51.   // Print their size
  52.   cout << "Ships: " << ships << endl << "Containers: " << containers << endl;
  53. }
  54.  
  55. int main() {
  56.   // Declare ship size and choice variables for the menu
  57.   SHIP ship_size;
  58.   int choice;
  59.  
  60.   do {
  61.     // Clear screen
  62.     system("cls");
  63.  
  64.     // Main menu
  65.     cout << "Menu: \n";
  66.     cout << "[1] Small Ship \n";
  67.     cout << "[2] Medium Ship \n";
  68.     cout << "[3] Large Ship \n";
  69.     cout << "\n[0] Exit \n";
  70.  
  71.     cout << "Enter your choice: ";
  72.     cin >> choice;
  73.  
  74.     switch (choice) {
  75.       case 1:
  76.         // Set chosen ship size
  77.         ship_size = SMALL_SHIP;
  78.         // Call function with the ship_size
  79.         computate_boxes(ship_size);
  80.         break;
  81.  
  82.       case 2:
  83.         // Set chosen ship size
  84.         ship_size = MEDIUM_SHIP;
  85.         // Call function with the ship_size
  86.         computate_boxes(ship_size);
  87.         break;
  88.  
  89.       case 3:
  90.         // Set chosen ship size
  91.         ship_size = LARGE_SHIP;
  92.         // Call function with the ship_size
  93.         computate_boxes(ship_size);
  94.         break;
  95.     }
  96.     // Inform user to input something so he can get back
  97.     // to the menu
  98.     cout << "\nEnter a key to continue....";
  99.     getch();
  100.  
  101.   } while(choice != 0);
  102.   return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement