battleship help

So I'm making a battleship program and I'm having a little trouble trying to figure out the attack sequence. I thought i had it down but when I tried to compile it compiles but i get a warning saying

[Warning] comparison is always true due to limited range of data.

I think I'm doing it right. but im not sure.

basically i have a hidden computer array and a computer array that is visable on screen. if the hit is equal to ascii value 177 (default look for the board) then mark it with a O (a miss)

else hit it with an X (a hit)

heres my code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
   void play()
     {    //declare varalbes
          int col; 
          int row; 
          
          //prompt user to enter column to attack with numbers
       cout<< "Enter a column to attack (ex. A=1, B=2 etc):  " <<endl;  
       cin >> col;
       col=col-1; 
       
       //prompt user to enter a column to attack 
       cout <<"Now enter a row: "<<endl; 
       cin >> row; 
       row = row -1; 
      
      //if coordinates player inputed doesnt equal ascii value 177 mark as hit.
       if (seaOpponenthide[row][col] != '177') //warning error here. 
           {
              seaOpponenthide[row][col]='X'; 
             seaOpponent[col][row]='X'; 
             cout <<"HIT!!" <<endl; 
              displayBoard();
             }
      //if coordinates player inputed equals ascii value 177 mark as miss. 
           else if (seaOpponenthide[row][col] = '177')
                {
                seaOpponenthide[row][col]='O'; 
              seaOpponent[col][row]='O'; 
             cout <<"Miss!!" <<endl;
              displayBoard();
              }
             
          play(); 
          }
Last edited on
'177' is not the ASCII value of 177. It's 3 characters '1', '7' and '7'.

If you want the ASCII value of 177, just use 177 (no quotes):

 
if (seaOpponenthide[row][col] != 177)  // <- no quotes 



EDIT: (although ASCII, of course, does not go above 127, but whatever ;P )
Last edited on
There's an extended ASCII value that goes higher than 177 but in not sure if that's what's giving me an error. I tried without the quotes and it still gives me an error. Not sure what's wrong..
I tried without the quotes and it still gives me an error


It shouldn't. What error are you getting?

EDIT:

oh wait... it would be signed.... so yeah that might be a problem.

try this instead:

 
if (seaOpponenthide[row][col] != (char)(177))
Last edited on
Hey thanks that worked. But what was it that you did? just declared that 177 was a character?
Topic archived. No new replies allowed.