I just received my homework which was battleship program. Started it a few days ago but my code seems having some logical error and i can't really find it. Can anybody fix it for me? Whenever the second time i entered, the program will just pop out: no such coordinate and i can't fix it. Help me
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int main()
{
int i, j;
auto char row = 'A';
int seas;
int seaIndex;
char sea[50];
for(i = 0; i < 50; i++)
{
sea[i] = '~';
}
for(j=0; j<10; j++){
printf(" 1 2 3 4 5\n\n");
for(i = 0; i < 50; i++)
{
if(i%5 == 0)
printf("%c", row++);
printf(" %c ", sea[i]);
if(i%5 == 4)
{
printf("\n");
}
}
printf("\n\nCoordinate Sir: ");
scanf("%c %d", &row, &seas);
fflush(stdin);
row = toupper(row) - 'A';
if(row < 0 || row > 9 || seas < 1 || seas > 5)
{
printf("\nNO SUCH COORDINATE!");
continue;
}
seaIndex = (row * 5) + (seas - 1);
if(sea[seaIndex] == 'X')
{
printf("YOU ALREADY SHOOT HERE");
continue;
}
sea[seaIndex] = 'X';
}
}