ランダム関数の結果を比較できないのはなぜですか?
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main (){
srand(time(NULL));
/*Player 1*/
int P1d1, P1d2, P1total;
P1d1 = 1 + rand() % 6; //Rolls Player 1's first die; random # between 1-6
P1d2 = 1 + rand() % 6; //Rolls Player 1's second die; random # between 1-6
P1total = P1d1 + P1d2; //Takes total of both rolls
/*Player 2*/
int P2d1, P2d2, P2total;
P2d1 = 1 + rand() % 6; //Rolls Player 2's first die; random # between 1-6
P2d2 = 1 + rand() % 6; //Rolls Player 2's second die; random # between 1-6
P2total = P2d1 + P2d2; //Takes total of both rolls
if (P1d1 == P1d2 && P2d1 =! P2d2){ <--- ERROR HERE
printf("Player 1 wins!\n");
}
else if (P2d1 == P2d2 && P1d1 =! P1d2) {
printf("Player 2 wins!\n");
}
}
エラーメッセージが表示されますerror: lvalue required as left operand of assignment
。
これは、割り当ての左側が変数でなければならないことを意味することを理解していますが、左側は変数 (int P1d1) です。助言がありますか?