"The basic program idea is for you to make repeated "guesses" as to where in an "ocean" of 100 "quadrants", as represented by a 10x10 array, the enemy has ships. When you guess correctly you will "hit" a ship. "Hit a ship enough times and you sink it. The goal of the game is to sink all the "enemy's" ships with as few guesses as possible.

The professor's program will repeatedly call your makeNextGuess function to both tell you the result of your last guess and receive information from you (well, your makeNextGuess function) what your next guess is. The prototype for makeNextGuess is:

**void makeNextGuess(int *, int *, Status);**

The two int * parameters will be (simulated) pass-by-reference parameters which your function will use to set the values (row, column) of the next guess. That Status value will be an enumerated type value passed by the professor's program to tell your makeNextGuess function the result of your last guess (MISS, HIT, or SUNK). The first time that the professor's program calls your function, to start the game, the Status passed will be NONE."

Before I start making up strategies for this, I just want to be able to check every single "quadrant" in the "ocean. I tried to write my function to do this, but I'm getting really weird output from the test program I'm using with the function ...I clearly wrote my function wrong. I can't figure out what I need to change, though. Here's my function:

#include "battleship.h" void makeNextGuess(int *nextRow, int *nextColumn, Status lastResult) { static int ocean[10][10] = { 0 }; int row; int column; int newColumn = 0; int saveColumn = 0; int saveRow = 0; *nextRow = 0; // sets up an arbitrary "first guess" *nextColumn = 0; // with row, column both = 0 ocean[*nextRow][*nextColumn] = lastResult; switch(lastResult) { case NONE: break; case MISS: for( row = 0; row < 10 - saveRow; row++ ) { for( column = 0; column < 10 - saveColumn; column++ ) { saveColumn = column; saveRow = row; *nextColumn = column; *nextRow = row; ocean[row][column]; } } break; case HIT: *nextColumn = saveColumn + 1; break; case SUNK: case SUNKCarrier: case SUNKBattleship: case SUNKFrigate: case SUNKSubmarine: case SUNKMineSweeper: default: printf("ERROR\n"); } }

This is the output I'm getting (sorry this post is taking up so much space!):

Try 0: Guess of 0, 0 yielded a 1.

Try 1: Guess of 5, 5 yielded a 2.

Try 2: Guess of 0, 1 yielded a 1.

Try 3: Guess of 5, 5 yielded a 1.

Try 4: Guess of 5, 5 yielded a 1.

Try 5: Guess of 5, 5 yielded a 1.

Try 6: Guess of 5, 5 yielded a 1.

Try 7: Guess of 5, 5 yielded a 1.

Try 8: Guess of 5, 5 yielded a 1.

Try 9: Guess of 5, 5 yielded a 1.

Try 10: Guess of 5, 5 yielded a 1.

Try 11: Guess of 5, 5 yielded a 1.

Try 12: Guess of 5, 5 yielded a 1.

Try 13: Guess of 5, 5 yielded a 1.

Try 14: Guess of 5, 5 yielded a 1.

Try 15: Guess of 5, 5 yielded a 1.

Try 16: Guess of 5, 5 yielded a 1.

Try 17: Guess of 5, 5 yielded a 1.

Try 18: Guess of 5, 5 yielded a 1.

Try 19: Guess of 5, 5 yielded a 1.

Try 20: Guess of 5, 5 yielded a 1.

Try 21: Guess of 5, 5 yielded a 1.

Try 22: Guess of 5, 5 yielded a 1.

Try 23: Guess of 5, 5 yielded a 1.

Try 24: Guess of 5, 5 yielded a 1.

Try 25: Guess of 5, 5 yielded a 1.

Try 26: Guess of 5, 5 yielded a 1.

Try 27: Guess of 5, 5 yielded a 1.

Try 28: Guess of 5, 5 yielded a 1.

Try 29: Guess of 5, 5 yielded a 1.

Try 30: Guess of 5, 5 yielded a 1.

Try 31: Guess of 5, 5 yielded a 1.

Try 32: Guess of 5, 5 yielded a 1.

Try 33: Guess of 5, 5 yielded a 1.

Try 34: Guess of 5, 5 yielded a 1.

Try 35: Guess of 5, 5 yielded a 1.

Try 36: Guess of 5, 5 yielded a 1.

Try 37: Guess of 5, 5 yielded a 1.

Try 38: Guess of 5, 5 yielded a 1.

Try 39: Guess of 5, 5 yielded a 1.

Try 40: Guess of 5, 5 yielded a 1.

Try 41: Guess of 5, 5 yielded a 1.

Try 42: Guess of 5, 5 yielded a 1.

Try 43: Guess of 5, 5 yielded a 1.

Try 44: Guess of 5, 5 yielded a 1.

Try 45: Guess of 5, 5 yielded a 1.

Try 46: Guess of 5, 5 yielded a 1.

Try 47: Guess of 5, 5 yielded a 1.

Try 48: Guess of 5, 5 yielded a 1.

Try 49: Guess of 5, 5 yielded a 1.

Try 50: Guess of 5, 5 yielded a 1.

Try 51: Guess of 5, 5 yielded a 1.

Try 52: Guess of 5, 5 yielded a 1.

Try 53: Guess of 5, 5 yielded a 1.

Try 54: Guess of 5, 5 yielded a 1.

Try 55: Guess of 5, 5 yielded a 1.

Try 56: Guess of 5, 5 yielded a 1.

Try 57: Guess of 5, 5 yielded a 1.

Try 58: Guess of 5, 5 yielded a 1.

Try 59: Guess of 5, 5 yielded a 1.

Try 60: Guess of 5, 5 yielded a 1.

Try 61: Guess of 5, 5 yielded a 1.

Try 62: Guess of 5, 5 yielded a 1.

Try 63: Guess of 5, 5 yielded a 1.

Try 64: Guess of 5, 5 yielded a 1.

Try 65: Guess of 5, 5 yielded a 1.

Try 66: Guess of 5, 5 yielded a 1.

Try 67: Guess of 5, 5 yielded a 1.

Try 68: Guess of 5, 5 yielded a 1.

Try 69: Guess of 5, 5 yielded a 1.

Try 70: Guess of 5, 5 yielded a 1.

Try 71: Guess of 5, 5 yielded a 1.

Try 72: Guess of 5, 5 yielded a 1.

Try 73: Guess of 5, 5 yielded a 1.

Try 74: Guess of 5, 5 yielded a 1.

Try 75: Guess of 5, 5 yielded a 1.

Try 76: Guess of 5, 5 yielded a 1.

Try 77: Guess of 5, 5 yielded a 1.

Try 78: Guess of 5, 5 yielded a 1.

Try 79: Guess of 5, 5 yielded a 1.

Try 80: Guess of 5, 5 yielded a 1.

Try 81: Guess of 5, 5 yielded a 1.

Try 82: Guess of 5, 5 yielded a 1.

Try 83: Guess of 5, 5 yielded a 1.

Try 84: Guess of 5, 5 yielded a 1.

Try 85: Guess of 5, 5 yielded a 1.

Try 86: Guess of 5, 5 yielded a 1.

Try 87: Guess of 5, 5 yielded a 1.

Try 88: Guess of 5, 5 yielded a 1.

Try 89: Guess of 5, 5 yielded a 1.

Try 90: Guess of 5, 5 yielded a 1.

Try 91: Guess of 5, 5 yielded a 1.

Try 92: Guess of 5, 5 yielded a 1.

Try 93: Guess of 5, 5 yielded a 1.

Try 94: Guess of 5, 5 yielded a 1.

Try 95: Guess of 5, 5 yielded a 1.

Try 96: Guess of 5, 5 yielded a 1.

Try 97: Guess of 5, 5 yielded a 1.

Try 98: Guess of 5, 5 yielded a 1.

Try 99: Guess of 5, 5 yielded a 1.

What's wrong with my function?! I don't even understand where the 5 is coming from, and the function just checks the same quadrant repeatedly for the most part.