In this program (Battleships game) I'm trying to place the ships in a linear fashion (numbers between 1 and 25).
I'm trying to use "if" statements to try and stop the player assigning more than one ship to any single number, but I can't for the life of me find any point of reference online that tells me that I can compare more than two variables. Here's my code snippet of what I've currently got;
1 2 3 4 5 6 7 8
cout << "Please enter a value between 1 and 25 to place the Destroyer" << endl;
cin >> placeDest;
if (placeDest == placeAirCarr, placeBatt)
{
cout << "Please choose a different number" << endl;
cin >> placeDest;
}
As you can see in the opening line of the "if" statement, I've currently got a comma separating two variables. These have already been set prior to the Destroyer so they have values loaded.
I'm currently getting an output of "Please choose a different number" no matter what number I input.
So, if anyone could depart their wisdom about comparing more than two variables that would be fantastic.
I'm not absolutely sure I got your just but I think I know what you're asking.
the || operator, pronounced as the OR operator, lets you have more than one condition in an if statement and if either one is true the body of the if statement will be entered
1 2 3 4 5
if ( placeDest == placeAirCarr || placeDest == placeBatt )
{
cout << "Please choose a different number" << endl;
cin >> placeDest;
}
the && operator (AND operator) is similar but enters the body of the if statement only if both conditions are true