Requirements:

For this exercise you are asked to write an application that allows the user to input the coordinates of points on a map. After the user has input all the coordinates they want to input, the program then displays a text-based map, filled with dots (represented by the '.' character), except for the locations the user entered the coordinates of, which are indicated by 'X' characters.

The dimensions of the map is 44 columns by 19 rows. You should use a two-dimensional array to mark the coordinates entered by the user (e.g. bool[,] map = new bool[19,44]).

The program collects input from the user by asking the user to input the X coordinate first, followed by the Y coordinate, followed by 'y' or 'n' to ask the user if there are any more points to be entered.

After the user has indicated (by responding 'n' on the third question) that there are no more points, the program should display the map, ask the user to press enter to exit, then close when the user presses enter.

Here is an example of a typical session (using a map of 10 columns by 5 rows to save space): see image.

Note that:

  • The coordinates are base 0 - that is, the lowest legal value for a coordinate is 0 and the highest legal value is the respective dimension of the map minus 1. Therefore, for the above example with a 10 x 5 map, the valid X values are 0-9 and the valid Y values are 0-4.
  • The coordinates 0, 0 refer to the top left of the map.

Your program should detect invalid input and out of range coordinates. When the user enters something other than a number as one of the coordinate inputs, your program should display the message 'Invalid input.' and ask the user again.

Likewise, if the user enters something that is a number but that number is outside the legal range for the map, your program should display the message 'Out of range.' and ask for that coordinate again.

Finally, for the question 'More? (y/n): ', if the user enters anything other than 'y' or 'n', your program should display the message 'Please answer with y or n.' and ask the user again.

Here's another example of a possible session with the program, again with a 10 x 5 map: see image.

Here's some hints specific to this exercise:

  • Make sure you refer to the coordinates within the array in the same order as the dimensions when you referenced the array. For example, if your array is a bool[19, 44] you will need to refer to it using the Y coordinate first, then the X coordinate, e.g. map[y, x]
  • For drawing the map remember that you can use Console.Write("."); or Console.Write("X"); to write a single character without ending the line, and then later use Console.WriteLine(); when you actually want to end the line.
  • When drawing the map you will want to use two loops, one inside the other.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.