为什么我不能比较随机函数的结果?
#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)。有什么建议么?