#include#include using namespace std; int askForChoice() { int choice; cout << "Please choose an option from the following menu:\n"; cout << "1. Option A\n"; cout << "2. Option B\n"; cout << "3. Option C\n"; cin >> choice; return choice; } int main() { int selectedOption = askForChoice(); cout << "You selected option " << selectedOption << endl; return 0; }
#includeIn this example, the askForChoice function prompts the user to select an option using letters instead of numbers. The function returns the selected option as an integer value. The main function calls askForChoice and displays the selected option to the user using printf. The stdio.h library is used in this example to handle input and output.#include int askForChoice() { char choice; printf("Please choose an option:\n"); printf("A. Option 1\n"); printf("B. Option 2\n"); printf("C. Option 3\n"); scanf("%c", &choice); return (int)choice - 64; } int main() { int selectedOption = askForChoice(); printf("You selected option %d\n", selectedOption); return 0; }