strings and arrays

so this is the code that i'm working on and i get this error about binary and the std string. i want to see of the guess matches one of the coordinates in the string and i'm not able to.

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
#include <iostream>
#include <string>
using namespace std;

int main() {
   int guesses, destroy, numAttempts = 11;
   string guess, i;
   string coordinate[3] = {"B1", "C4", "D3"};
   
   cout << "Let's play a quick game of battleship... destroyer!" << endl;
   cout << "The objective of this game is to destroy the 3 ships on the computers grid. You have 10 chances to do so." << endl;
   cout << "Enter in a coordinate between A-1 and D-4 (i.e. C4): ";
   cin >> guess;
   
   guesses = 0;
   destroy = 0;

  if (guess == coordinate) {
     cout << "Target hit! Next target: ";
     cin >> guess;
     destroy++;
     guesses++;
  }
  else {
     cout << "Target missed. Try again: ";
     cin >> guess;
     guesses++;
  }

}
> i get this error about binary and the std string
... ¿what error?
you are not matching all the coordinates. use a loop.
something like
if(guess == coordinate[i])
1
2
3
4
5
string guess
/*...*/
string coordinate[3]
/*...*/
if (guess == coordinate)


"coordinate" has not the same type of "guess".

You can't check their equality state.
Thanks EssGeEich.
Is there anyway around that?
I guess you just want to check if 'guess' is any of the strings inside 'coordinate'.

Then:

1
2
3
4
5
6
7
8
9
10
11
bool Inside = 0;
for(unsigned int i = 0; i < (sizeof(coordinate) / sizeof(coordinate[0])); ++i)
{
    if(coordinate[i] == guess)
    {
        Inside = 1;
        break;
    }
}
if(Inside) {
//... 
Topic archived. No new replies allowed.