Multidimensional arrays: Implement a program that keeps track of shots fired in
ID: 3534582 • Letter: M
Question
Multidimensional arrays: Implement a program that keeps track of shots fired in a battleship game. Your program should ask the user if she wants to take another shot, ask for shot coordinates and then print the locations of all shots fired so far in a grid. Here is an example dialog:
Refer to this program for multidimensional array example usage.
// elementary multidimensional array usage
#include <iostream>
using namespace std;
int main (void){
const int length=5, width=2;
int a[length][width]; // declares an integer array of 5 rows and 2 columns
// initializes the arry
for(int i=0; i < length; i++)
for(int j=0; j < width; j++)
a[i][j] = i*width+j;
// outputs each array element's value
for (int i=0; i < length; i++)
for (int j=0; j < width; j++)
cout << "a[" << i << "][" << j << "] = "
<< a[i][j]<< endl;
}
Explanation / Answer
http://ideone.com/So7RYv
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.