#include#include int main() { char choice; std::cout << "Welcome to my program!" << std::endl; std::cout << "Please select an option:" << std::endl; std::cout << "1. Option 1" << std::endl; std::cout << "2. Option 2" << std::endl; std::cout << "3. Option 3" << std::endl; do { choice = _getch(); } while (choice != '1' && choice != '2' && choice != '3'); std::cout << "You selected option " << choice << "." << std::endl; return 0; }
#includeIn this example, the program simulates a simple game where the player can move around a grid using the arrow keys (up, down, left, and right). The position of the player is stored in two variables (player_x and player_y), and the program updates these variables based on the user's input. The package library for this function is again the "conio.h" library, which provides console input/output functions for Windows-based systems.#include int main() { char move; int player_x = 0; int player_y = 0; std::cout << "Welcome to my game!" << std::endl; std::cout << "Use the arrow keys to move." << std::endl; do { move = _getch(); switch(move) { case 'w': player_y--; break; case 's': player_y++; break; case 'a': player_x--; break; case 'd': player_x++; break; } std::cout << "Player position: (" << player_x << ", " << player_y << ")" << std::endl; } while (move != 'q'); std::cout << "Thanks for playing!" << std::endl; return 0; }