lundi 7 décembre 2015

If-else statement in c++

i have a problem with the next question, i need to solve it by using if/else, i wrote the code but i don't know if it's the solve of the question or not:

Write a program in which the user enters the coordinates of the black pawns (a, b) on the chessboard.

The program must determine whether the pawn may move to get to one field (c, d):
1. In the ordinary move;
2. When it "hit" piece or pawn opponent.

Note: Black pawn move on the board from the bottom up.

char CoordinY;
int CoordinX;

if (CoordinY > 'b' && CoordinX <= 1 && CoordinX>8)
{
    cout << "Error . . . \n";
}
else
{
    if (CoordinX >= 2 && CoordinX <= 8 && CoordinY == 'a' || CoordinY == 'b'*)  
    {
        // arbitrary move:
        cout << "will not get to the field (c, d) in the ordinary move.\n"; 
        // when it "hits" enemy's figure or pawn
        cout << "will not get to the field (c, d) when ше hit a figure or pawn opponent.\n"; 
    }
    else if (CoordinX>1 && CoordinX < 8 && CoordinY == 'b')
    {
        // arbitrary move
        cout << "will not get to the field (c, d) in the ordinary move.\n";
        // when it "hits" enemy's figure or pawn
        cout << "will not get to the field (c, d) when it hit a figure or pawn opponent.\n";
    }

Aucun commentaire:

Enregistrer un commentaire