Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ______ _ _____ _ _
- | ___ \ | | |_ _| | |
- | |_/ / __ ___ __ _ _ __ __ _ _ __ ___ | |__ _ _ | | | | | _____
- | __/ '__/ _ \ / _` | '__/ _` | '_ ` _ \ | '_ \| | | | | | | | |/ / _ \
- | | | | | (_) | (_| | | | (_| | | | | | | | |_) | |_| | _| |_| | < (_) |
- \_| |_| \___/ \__, |_| \__,_|_| |_| |_| |_.__/ \__, | \___/|_|_|\_\___/
- __/ | __/ |
- |___/ |___/
- */
- #include <iostream>
- #include <conio.h>
- using namespace std;
- // Enumerate all container sizes
- enum CONTAINER {
- LARGE_CONTAINER = 50,
- MEDIUM_CONTAINER = 20,
- SMALL_CONTAINER = 5,
- SINGLE_CONTAINER = 1
- };
- // Enumerate all ship sizes
- enum SHIP {
- LARGE_SHIP = 1500,
- MEDIUM_SHIP = 1000,
- SMALL_SHIP = 500
- };
- void computate_boxes(SHIP ship_size) {
- // Clear Screen
- system("cls");
- // Declare number of boxes, number of containers and number of ships
- int number_of_boxes, containers, ships;
- // Get container size relatively on ship size.
- CONTAINER container_size = (ship_size == LARGE_SHIP ? LARGE_CONTAINER : ship_size == MEDIUM_SHIP ? MEDIUM_CONTAINER : ship_size == SMALL_SHIP ? SMALL_CONTAINER : SINGLE_CONTAINER);
- cout << "Enter the amount of boxes: ";
- cin >> number_of_boxes;
- // Validate Input
- !cin || number_of_boxes < 500 ? "Error: Input over 500 boxes, please!\n" : "";
- // Calculate ships and containers with the number of boxes
- ships = number_of_boxes / ship_size;
- containers = number_of_boxes / container_size;
- // Print their size
- cout << "Ships: " << ships << endl << "Containers: " << containers << endl;
- }
- int main() {
- // Declare ship size and choice variables for the menu
- SHIP ship_size;
- int choice;
- do {
- // Clear screen
- system("cls");
- // Main menu
- cout << "Menu: \n";
- cout << "[1] Small Ship \n";
- cout << "[2] Medium Ship \n";
- cout << "[3] Large Ship \n";
- cout << "\n[0] Exit \n";
- cout << "Enter your choice: ";
- cin >> choice;
- switch (choice) {
- case 1:
- // Set chosen ship size
- ship_size = SMALL_SHIP;
- // Call function with the ship_size
- computate_boxes(ship_size);
- break;
- case 2:
- // Set chosen ship size
- ship_size = MEDIUM_SHIP;
- // Call function with the ship_size
- computate_boxes(ship_size);
- break;
- case 3:
- // Set chosen ship size
- ship_size = LARGE_SHIP;
- // Call function with the ship_size
- computate_boxes(ship_size);
- break;
- }
- // Inform user to input something so he can get back
- // to the menu
- cout << "\nEnter a key to continue....";
- getch();
- } while(choice != 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement