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

In C++ I am using a menu to have a user input 5 variables for the Langton\'s ant

ID: 3709690 • Letter: I

Question

In C++ I am using a menu to have a user input 5 variables for the Langton's ant simulation but it will not exit back to the main function after the last input has been input. How can I correct this? I have included a copy of my code for reference.

/*************************************************************************

**                   user input information menu

**   this program will print a menu of information need in order to start

** the simulation

*************************************************************************/

int Ant::userInputMenu(int choice)

{

   int bRows, bCols, maxSteps, startRow,startCol;

  

   cout << "           Menu for Langton's Ant Simulation ";

   cout << "1. Enter number of rows for the board. ";

   cout << "2. Enter the number of columns for the board. ";

   cout << "3. Enter the maximum number of steps the ant may take. ";

   cout << "4. Enter the starting row for the ant. ";

   cout << "5. Enter the startig column for the ant. ";

   cout << "6. Quit simulation ";

   cout << "Please enter your choice ";

   cin>> choice;

  

   //validate and process menu choice

   //userInputValidation(choice);

  

  

   bool displayMenu = false;

   bool done = false;

   while(( choice >= 1 && choice < 7 ) || done == false){

       if(choice < 0 || choice > 6){

           cout << "Invalid choice. The valid choices are 1 - 6 ";

           cout << "Please enter a valid menu choice. ";

           cin >> choice;

       }

      

       cout << "Choice is currrently: " <<choice << " ";

       if(displayMenu == true){

           cout << "           Menu for Langton's Ant Simulation ";

           cout << "1. Enter number of rows for the board. ";

           cout << "2. Enter the number of columns for the board. ";

           cout << "3. Enter the maximum number of steps the ant may take. ";

           cout << "4. Enter the starting row for the ant. ";

           cout << "5. Enter the startig column for the ant. ";

           cout << "6. Quit simulation ";

           cout << "Please enter your choice ";

           cin>> choice;

           displayMenu = false;

       }

      

       if(choice == 1){

           cout << "Enter the number of rows for the board ";

           cin >> bRows;

           displayMenu = true;

       } else if(choice == 2){

       cout << "Enter the number of columns on board: ";

           cin >>bCols;

           displayMenu = true;

       }else if(choice == 3){

       cout << "Enter maxium steps allowed: ";

           cin >> maxSteps;

           displayMenu = true;

       }else if(choice == 4){

       cout << "Enter the starting row for the ant ";

           cin >> startRow;

           displayMenu = true;

       }else if(choice == 5){

       cout << " Enter the starting column for the ant ";

           cin >> startCol;

           displayMenu = true;

           if(bRows > 0 && bCols > 0 && maxSteps >0 && startRow > 0 && startCol > 0){

               cout <<"breaking out of loop ";

               done = true;

               break;

       }else if(choice == 6){

           cout << "Quiting simulation ";

           exit(0);

           }

       //cout << "Choice is now: " <<choice << " ";

       //if(bRows > 0 && bCols > 0 && maxSteps >0 && startRow > 0 && startCol > 0){

       //   cout <<"breaking out of loop ";

       //   done = true;

       //   choice = 0;

       }

       //if(choice == 0){

       //   break;

       //}

   }

   cout << "Done!";

  

   return 0;

  

}

** this program

Thank you!

Explanation / Answer

Hi always use indentation in the code this is error due to bad indentation. So you miss place one } in if else.

Now i correct that but always use indentation

Your code :