新人求助枚举类型问题
#include <stdio.h>#include <stdlib.h>
#include <time.h>
enum Status {CONTINUE,WON,LOST};
int rollDice(void);/*函数声明*/
int main(void)
{
int sum;
int mypoint;
enum Status gameStatus;
srand( time(NULL));
sum = rollDice();
switch(sum) {
case 7:
case 11:
gameStatus = WON;
break;
case 2:
case 3:
case 12:
gameStatus = LOST;
break;
default:
gameStatus = CONTINUE;
mypoint = sum;
printf("point is %d\n",mypoint);
break;
}
while (gameStatus == CONTINUE) {
sum = rollDice();
if (sum ==mypoint) {
gameStatus = WON;
}
else {
if( sum==7){
gameStatus = LOST;
}
}
}
if ( gameStatus==WON) {
printf("Player wins\n");
}
else {
printf("Player loses\n");}
return 0;
}
int rollDice(void)
{
int die1;
int die2;
int workSum;
die1 = 1+ (rand()%6);
die2 = 1+ (rand()%6);
workSum = die1+die2;
printf(" Player rolled %d+%d =%d\n",die1,die2,workSum);
return workSum;
}
现在这个程序是可以运行编译成功的,但是呢为什么做了两次enum定义呢??分别是enum Status {CONTINUE,WON,LOST};和enum Status gameStatus; 为什么我直接enum gamesStatus,而不是用Status做一个过渡时 程序编译器就告诉我gameStatus未定义呢 这是为什么呢 谢谢