Pradius
  • Pradius
/* Write a program that displays a menu which allows the user to move one unit north, east, south or west. Each time the player enters a selection, update the coordinates of the user and output the current position. Start the player at the origin of the coordinate system. Your program’s output should look like the following: */ #include #include using namespace std; int main() { char cUserInput; int x; int i; int nPos[4][2]= // Represents positions or coordenates { {0,0}, //N {0,1}, //E {1,0}, //W {1,1} //S }; //Ask user for input for(i=0; i >=0; ++i) { cout << "Move (N)orth, (S)outh, (W)est, (E)ast, (Q)uit? "; cout << endl; cin >> cUserInput; switch(cUserInput) // Assign a value to X in order to make decisions. { case ("n"||"N"): x = 0; break; case ("e"||"E"): x = 1; break; case ("w"||"W"): x = 2; break; case ("s"||"S"): x = 3; break; case ("q"||"Q"): x = 4; break; default: x = 5; break; } if (x = 4){ //desicions based on X value cout << "Exiting...."; break; } else if(x > 4){ cout<< "Please insert a valid position"; continue; } else { cout << "Current position: ("; for(i=0; i <2; ++i){ cout << nPos[x][i]; cout << ","; } cout << ")" cout << endl; continue; } } }
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Pradius
  • Pradius
In the "switch" statement Im getting an error: duplicate case value, previously used here. any comments??? Thanks
eSpeX
  • eSpeX
You cannot use conditional statements in a switch. Convert your user input to one case and switch that.
e.mccormick
  • e.mccormick
No need to convert. There is another way: case "n": case "N": x = 0; break; case "e": case "E": etc. This is a pretty comon method as well. Both work fine.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
yes the above way mentioned is known as fall through
rsmith6559
  • rsmith6559
You also can put the code that the if and else if would execute into their appropriate case block.
Pradius
  • Pradius
Thanks guys. Now I have another problem but I'll work on that.

Looking for something else?

Not the answer you are looking for? Search for more explanations.