Question: In this code I am trying to make my q0 case to jump to my q1 case if the user inputs 1. However, when the

In this code I am trying to make my q0 case to jump to my q1 case if the user inputs 1. However, when the user inputs 1 the code stops from running and doesn't do anything.

current code in c++

#include

using namespace std;

#define q0 0 // start

#define q1 1 // twisty tunnel

#define q2 2 // Rapid River

int menu()

{

bool start = true;

bool wentBack = false;

bool wentForward = true;

bool getSword = false;

bool keyIsFound = false;

int direction = -1;

while (direction < 1 || direction > 4)

{

cout << "please choose a direction by the number" << endl;

cout << " 1 East" << endl;

cout << " 2 WEST" << endl;

cout << " 3 NORTH" << endl;

cout << " 4 SOUTH" << endl;

cout << "choose a direction: ";

cin >> direction;

int stateNumber = q0;

switch (stateNumber)

{

case q0:

if (direction == 1)

{

wentForward = true;

stateNumber = q1;

}

break;

case q1:

if (wentForward)

{

cout << "You are in the Twisty Tunnel" << endl;

}

break;

case q2:

default:

break;

}

}

return direction;

}

int main()

{

int direction = menu();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!