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

// UserMenu_Solution.cpp : This code contains five errors before it will work as

ID: 3755051 • Letter: #

Question

// UserMenu_Solution.cpp : This code contains five errors before it will work as desired. Find those errors, // document a description of the errors and their fix, and fix them. Try using the debugger to // step through the program to find the bugs. As you step through, take notice of the information // you can see

. //This program builds a menu based on switchcase statements to determine where a user wants to go in the program. // Program options are then to solve the Tower of Hanoi problem, view the user profile, or exit the program.

#include "stdafx.h"

#include <cstdlib>

#include <iostream>

void Tower(int, char, char, char);

int main()

{

int choice;

cout << "1. Solve the Tower of Hanoi" << endl;

cout << "2. View Your Profile" << endl;

cout << "3. Exit" << endl;

cout << "Enter your choice : " << endl;

cin >> choice;

switch (Choice)

{

case 1:

system("cls");

int numDiscs;

cout << "**Tower of Hanoi** ";

cout << Enter the number of discs : ;

cin >> numDiscs;

cout << " ";

Tower(numDiscs, 'A', 'B', 'C');

break;

case :

cout << "Username: Player 1" << endl;

cout << "Gamertag: ImTheBest" << endl;

cout << "No. Hours Played: 173" << endl;

break;

case 3:

cout << "Now Exiting." << endl;

break;

default:

cout << "You did not choose anything...so exit this program." << endl;

}

return 0;

}

void Tower(int numDiscs, char from, char aux, char to){

if (numDiscs == 1){

cout << " Move disc 1 from " << from << " to " << to << " ";

return;

}

else{

tower(numDiscs - 1, from, to, aux);

cout << " Move disc " << numDiscs << " from " << from << " to " << to << " ";

Tower(numDiscs - 1, aux, from, to);

}

}

Explanation / Answer

Hey,

Below is the edited error free code


#include <cstdlib>

#include <iostream>
using namespace std;
void Tower(int, char, char, char);

int main()

{

int choice;

cout << "1. Solve the Tower of Hanoi" << endl;

cout << "2. View Your Profile" << endl;

cout << "3. Exit" << endl;

cout << "Enter your choice : " << endl;

cin >> choice;

switch (choice)

{

case 1:

system("cls");

int numDiscs;

cout << "**Tower of Hanoi** ";

cout <<" Enter the number of discs : ";

cin >> numDiscs;

cout << " ";

Tower(numDiscs, 'A', 'B', 'C');

break;

case 2:

cout << "Username: Player 1" << endl;

cout << "Gamertag: ImTheBest" << endl;

cout << "No. Hours Played: 173" << endl;

break;

case 3:

cout << "Now Exiting." << endl;

break;

default:

cout << "You did not choose anything...so exit this program." << endl;

}

return 0;

}

void Tower(int numDiscs, char from, char aux, char to){

if (numDiscs == 1){

cout << " Move disc 1 from " << from << " to " << to << " ";

return;

}

else{

Tower(numDiscs - 1, from, to, aux);

cout << " Move disc " << numDiscs << " from " << from << " to " << to << " ";

Tower(numDiscs - 1, aux, from, to);

}

}

The 5 errors are

Kindly revert for any queries

Thanks.