non-lvalue in assignemt

What does non-lvalue in assignment error mean? How should it be fixed. I can't find a useful solution on the internet and any help would be greatly appreciated. Thank you!

P.S. I've highlighted the problem line.


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

#include <iostream>
using namespace std;

int main ()
{
    //Ask for type of piece and position
    cout << "Please enter P for Pawn, N for Knight, B for Bishop, R for Rook, Q for Queen and K for King." << endl;
    char piece;
    cin >> piece;
    char y1;
    int x1;
    cout << "Enter the position of the piece,  e.g. a7" << endl;
    cin >> y1 >> x1;

    //Final Position
    char y2;
    int x2;
    cout << "Enter the final position." << endl;
    cin >> y2 >> x2;

    //Checking for validity


   

    if (piece = "P" &&  y1 == y1 and x1 = x1 + 1)



            cout << "The move is valid." << endl;
    else
            cout << "The move is invalid." << endl;

return 0;
}
Last edited on
1) Assignment vs. equality operators.

2) Strings vs. chars

3) Initial position vs. final position

These should be enough to fix your code. And these 3 are only targeted at your one line.
What if I wanted to check what the entered piece was? Considering that piece = "P" or piece == "P", piece = P or piece == P wouldn't work, what should I write to access the type of piece?
closed account (48T7M4Gy)
piece == 'P'

not
piece == "P" etc
Last edited on
That doesn't fix the error either.
closed account (48T7M4Gy)
Try the P test just on it's own without the reference to x1 and y1. That way you can see if it is the problem.

if (piece = "P" && y1 == y1 and x1 = x1 + 1)
And why have y1 == y1 - Always true??
Even x1 == x1 + 1 - Always false??
Sorry, there was another problem in there too which was causing the error. This fixed it. Thank you!
Topic archived. No new replies allowed.