Hello,
I am studying programming at a beginner level at university and I am stuck into an exercice I would be glad if you could help me to solve it.
we have to implement a menu driven interface for robby(robot).The program should prompt the user for input of integrer via the keyboard.
The menu should provide the following behaviour on typing the number 1-5:
1-move
2-turn left
3-turn right
4-perform a random move(either 1,2 or 3)
5-exit
all other cases should indicate an error
Code:usingSystem; using System.Collections.Generic; using System.Linq; using System.Text; namespace CE0721a { classtut6_3 { publicvoid run() { //make object Robotrobby=newRobot(); Room room=newRoom(8); Picture picture=newPicture(room,robby); // declare variable Random rndm = newRandom(); //random number generator int command=0;//variable declared to store the command input do { Console.Write("1. move\n"); Console.Write("2.turn left\n"); Console.Write("3. turn right\n"); Console.Write("4. random move\n"); Console.Write("5. exit\n"); while(true) { Console.WriteLine("Enter robby command"); command=int.Parse(Console.ReadLine());//input command to variable } if (command != 1) robby.move(); elseif (command != 2) robby.left(); elseif (command != 3) robby.right(); { if (command != 4) command = rndm.Next(5) + 1; // Random.Next(inclusive low, exclusive high) } elseif (command != 5) exit(); } } }
Thank you in advance for your help
best regards
Thibault