Dealing with arrayys !!

I do not know about the game battleship because I never played before, but how would I start off the code

Question
Using a two-dimensional array as the basis for creating the game battleship. In the game of battleship, a "-" character entry in the array represents ocean(i.e. not a ship), a "#" character represents a place in the ocean where part of ship is present and a "H" character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, all "H" characets means the ship has been suck. Declare a two dimensional array that is 25x25 that represent the entire ocean and if a statement that prints "HIT" if a torpedo hits a ship given the coordinate X and Y. Write a C++ program that will read in a file representing a game board with 25 lines where each line has 25 characters corresponding to the description above.

You should write a function called Fire that will take an X and Y coordinate and print "HIT" if a ship is hit and "MISS" if a ship is missed. If a ship is HIT you should update the array with an "H" chacacter to indicate the ship was hit. If a ship is hit that has already been hit at that location you should print " HIT AGAIN". You should write a second function called FleetSunk that will determine if all the ships have been sunk. Your C++ program must then call these functions until all the ships have been suck at which point the program should display "The fleet was destoryed".
closed account (48T7M4Gy)
When is your homework due?
Well the instructions sound quite clear.

First I would declare the game board and write a function that will read the game from the file.
A good starting point to learn about files is here:
http://www.cplusplus.com/doc/tutorial/files/
The part with the output you can skip since the program doesn't need to output something to a file.
Tomorrow we just got the assignment today
closed account (48T7M4Gy)
Well, you better get into it Princess.

Step by step, just as Tom says. Possibly, a plan might be very first step. You can do that in a few minutes by parsing the question. I.e. split the exercise into separate active sentences and number them.

1. setup a 2d array
2. setup characters for oceans, etc etc
3. blah , blah, blah

Hop into it, time is pressing if you want to meet your time target.

Keep in touch, show us how you are going and let us know if you get stuck.

Cheers and all the best :)

PS Hopefully you literally know how to 'start the actual code' but that comes after you have a plan so it's a tad early to get into that at the moment.
Last edited on
How I suppose to get into if I never played the game before and I dont know what it is about ??
closed account (48T7M4Gy)
How I suppose (sic) to get into (it) if I (have) never played the game before and I don't know what it is about ??


You're using up your valuable time Princess.

In the first instance I would read the question and follow the suggestions we have made subsequent to that. My opinion is that there is enough detail in that to enable you to make the start you so urgently require, but I accept that opinions may vary in the rich tapestry of life.

Of course, there is always:

http://lmgtfy.com/?q=http%3A%2F%2Flmgtfy.com%2F%3Fq%3Dhow%2Bto%2Bplay%2Bgame%2Bof%2Bbattleship%2Bfor%2Bbeginners

Great question Princess
Cheers :)
Topic archived. No new replies allowed.