解决办法:
#include <iostream>
#include <cstdlib>
using namespace std;
unsigned rollDic();
int main(){
enum GameStatus{WIN,LOSE,PLAYING};
GameStatus gs = PLAYING;
unsigned num;
unsigned sum,result;
cout<<"Please Enter a random number: "<<endl;
cin>>num;
srand(num);
sum = rollDic();
switch (sum)
{
case 7:
case 11:
gs = WIN;
break;
case 2:
case 3:
case 12:
gs = LOSE;
break;
default:
result = sum;
gs = PLAYING;
break;
}
while (gs == PLAYING)
{
int i = rollDic();
if (i == result)
{
gs = WIN;
}else if (i == 7)
{
gs = LOSE;
}
}
if (gs == WIN)
{
cout<< "player win!"<<endl;
}else{
cout<< "player lose!"<<endl;
}
return 0;
}
unsigned rollDic(){
unsigned d1 = 1+ rand()%6;
unsigned d2 = 1+ rand()%6;
unsigned sum = d1+d2;
cout << "d1 + d2 = "<<sum<<endl;
return sum;
}