Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help creating an interactive menu for C++ where I can use the arrow keys

ID: 3623803 • Letter: I

Question

I need help creating an interactive menu for C++ where I can use the arrow keys and enter key to make my selections.

So the menu pops up with 3 options
Start Game
Options
Help

Moving the key selects and highlights that option and pressing enter advances you through the menu. If you can just make these 3 options output a statement say if you highlight start game and press enter it would output the text "Start Game", highlighting options and pressing enter outputs "options", and help outputs "help".
What I'm having the most trouble with is finding out how to map the keys and have the keys do what they are supposed to in the menu. I made a program that uses getch() to recognize the keys, but I don't know how to then use that to navigate a menu.

Can you please put an explanation of what your code is doing so I could follow along.

 

Here's the code i made without the interactive menu ... I haven't figured out how to advance using enter so i used y.  I need help figuring out how I can make my way back to the menu where the user has the option to select Start Game,Options,or Help so I need to be able to make my way back if i go into help or options and need to go back in order to start game.

 

#include
#include // used for system cls to clear screen
#include
using namespace std;
void Menu(int Main_Menu);

int main()
{
    int Main_Menu;
    char Key_Pressed=0;
    unsigned char cIn_1, cIn_2;
    unsigned char arrow_1, up,down, left, right, enter;
    arrow_1 = 224;
    up = 72;
    down = 80;
    left = 75;
    right = 77;
    enter = 13;

    do
    {
    system("cls");
    cout << "Welcome to Battleship" << endl;
    cout << "Created By: " << endl;
    cout << "Press Y to continue" << endl;

    cin >> Key_Pressed;
    }
    while(Key_Pressed!=121);
    if (Key_Pressed==121) // continues if Y is pressed
    {
    system("cls");
    Menu(Main_Menu);
    }


    return 0;

}

void Menu(int Main_Menu)
{
int Menu_Choices=0;
do
    {
    cout << "Enter your choice"<< endl;
    cout << "1 Play Game" << endl;
    cout << "2 Options" << endl;
    cout << "3 Help" << endl;
    cin >> Menu_Choices;
        if (Menu_Choices <= 0 || Menu_Choices > 3)
            {
            system("cls");
            cout << "Invalid Choice. Please Try Again..." << endl;
            }

    }
    while (Menu_Choices <= 0 || Menu_Choices > 3 );

    switch (Menu_Choices)
    {
    case 1:
         system("cls");
         cout << "Play Game..." << endl;
         break;
    case 2:
         system("cls");
         cout << "Options..." << endl;
         break;
    case 3:
         system("cls");
         cout << "Help..." << endl;
         break;
    }
}

Explanation / Answer

#include using namespace std; int ConvertedTemp(int, char); void PrintMenu(); int main () { bool b = true; bool b2 = false; char letter; // Place to store input letter char Units; int tempIn, tempOut; PrintMenu(); do{ b2 = false; cin >> letter; switch(letter) { case 'q':case 'Q': b = false; break; case'r':case'R': PrintMenu(); b2 = true; break; case'c':case'C': Units = 'F'; cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote