
expected primary-expression before '[' token 枚举类型总是出现这个错误,当然我程序还没编完 40
#include<iostream.h>#include<string.h>#include<windows.h>#include<time.h>typedefenumP...
#include<iostream.h>
#include<string.h>
#include<windows.h>
#include<time.h>
typedef enum Phstate{thinking,waiting,eating};
Phstate phstate[5];
typedef enum Stickstate{used,nused};
Stickstate stickstate[5];
int stick[5];
int Ph[5];
int i,m;
void deadclock();
void ordered_allocation_philosopher();
void pre_allocation_philosopher();
void pre_hungry();
void quit();
void take();
int main(int argc,char*argv[])
{
int a;
x:cout<<"\n\n\n\n"
"\t\t\t@*******哲学家死锁问题*************@\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 请选择操作(1-5) $\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 1--死锁现象演示 $\n"
"\t\t\t$ 2--按序分配法防止死锁 $\n"
"\t\t\t$ 3--预分配法防止死锁 $\n"
"\t\t\t$ 4--防止饿死现象演示 $\n"
"\t\t\t$ 5--退出系统 $\n"
"\t\t\t$----------------------------------$\n"
"\t\t\t@**********************************@\n"<<endl;
cin>>a;
switch (a){
case '1':
deadclock();break;
case '2':
ordered_allocation_philosopher();break;
case '3':
pre_allocation_philosopher();break;
case '4':
pre_hungry();break;
case '5':
quit();break;
default:
goto x;
}
system("pause");
}
void take()
{
cout<<"申请左边筷子"<<endl;
if(Stickstate[i] == nused)
{
Stickstate[i] == used;
cout<<"拿起左边筷子"<<endl;
}
cout<<"申请右边筷子"<<endl;
if(Stickstate[i-1] == nused)
{
Stickstate[i-1] == used;
cout<<"拿起右边筷子"<<endl;
}
}
void deadclock()
{
for(i=0;i<5;i++)
{
if(i%2 == 0])
{
Phstate[i] == thinking;
Stickstate[i] == nused;
{
cout<<"第"<<i<<"位哲学家处于思想状态"<<endl;
}
}
else
{
Phstate[i] == waiting;
Stickstate[i] == nused;
cout<<"第"<<i<<"位哲学家处于等待状态"<<endl;
take();
}
}
} 展开
#include<string.h>
#include<windows.h>
#include<time.h>
typedef enum Phstate{thinking,waiting,eating};
Phstate phstate[5];
typedef enum Stickstate{used,nused};
Stickstate stickstate[5];
int stick[5];
int Ph[5];
int i,m;
void deadclock();
void ordered_allocation_philosopher();
void pre_allocation_philosopher();
void pre_hungry();
void quit();
void take();
int main(int argc,char*argv[])
{
int a;
x:cout<<"\n\n\n\n"
"\t\t\t@*******哲学家死锁问题*************@\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 请选择操作(1-5) $\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 1--死锁现象演示 $\n"
"\t\t\t$ 2--按序分配法防止死锁 $\n"
"\t\t\t$ 3--预分配法防止死锁 $\n"
"\t\t\t$ 4--防止饿死现象演示 $\n"
"\t\t\t$ 5--退出系统 $\n"
"\t\t\t$----------------------------------$\n"
"\t\t\t@**********************************@\n"<<endl;
cin>>a;
switch (a){
case '1':
deadclock();break;
case '2':
ordered_allocation_philosopher();break;
case '3':
pre_allocation_philosopher();break;
case '4':
pre_hungry();break;
case '5':
quit();break;
default:
goto x;
}
system("pause");
}
void take()
{
cout<<"申请左边筷子"<<endl;
if(Stickstate[i] == nused)
{
Stickstate[i] == used;
cout<<"拿起左边筷子"<<endl;
}
cout<<"申请右边筷子"<<endl;
if(Stickstate[i-1] == nused)
{
Stickstate[i-1] == used;
cout<<"拿起右边筷子"<<endl;
}
}
void deadclock()
{
for(i=0;i<5;i++)
{
if(i%2 == 0])
{
Phstate[i] == thinking;
Stickstate[i] == nused;
{
cout<<"第"<<i<<"位哲学家处于思想状态"<<endl;
}
}
else
{
Phstate[i] == waiting;
Stickstate[i] == nused;
cout<<"第"<<i<<"位哲学家处于等待状态"<<endl;
take();
}
}
} 展开
2个回答
2011-12-21
展开全部
#include<iostream.h>
#include<string.h>
#include<windows.h>
#include<time.h>
typedef enum Phstate{thinking,waiting,eating};
Phstate phstate[5];
typedef enum Stickstate{used,nused};
Stickstate stickstate[5];
int stick[5];
int Ph[5];
int i,m;
void deadclock();
void ordered_allocation_philosopher();
void pre_allocation_philosopher();
void pre_hungry();
void quit();
void take();
int main(int argc,char*argv[])
{
int a;
x:
cout<<"\n\n\n\n"
"\t\t\t@*******哲学家死锁问题*************@\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 请选择操作(1-5) $\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 1--死锁现象演示 $\n"
"\t\t\t$ 2--按序分配法防止死锁 $\n"
"\t\t\t$ 3--预分配法防止死锁 $\n"
"\t\t\t$ 4--防止饿死现象演示 $\n"
"\t\t\t$ 5--退出系统 $\n"
"\t\t\t$----------------------------------$\n"
"\t\t\t@**********************************@\n"<<endl;
cin>>a;
switch (a){
case '1':
deadclock();break;
case '2':
ordered_allocation_philosopher();break;
case '3':
pre_allocation_philosopher();break;
case '4':
pre_hungry();break;
case '5':
quit();break;
default:
goto x;
}
system("pause");
}
void take()
{
cout<<"申请左边筷子"<<endl;
if(stickstate[i] == nused)
{
stickstate[i] == used;
cout<<"拿起左边筷子"<<endl;
}
cout<<"申请右边筷子"<<endl;
if(stickstate[i-1] == nused)
{
stickstate[i-1] == used;
cout<<"拿起右边筷子"<<endl;
}
}
void deadclock()
{
for(i=0;i<5;i++)
{
if(i%2 == 0)
{
phstate[i] == thinking;
stickstate[i] == nused;
{
cout<<"第"<<i<<"位哲学家处于思想状态"<<endl;
}
}
else
{
phstate[i] == waiting;
stickstate[i] == nused;
cout<<"第"<<i<<"位哲学家处于等待状态"<<endl;
take();
}
}
}
#include<string.h>
#include<windows.h>
#include<time.h>
typedef enum Phstate{thinking,waiting,eating};
Phstate phstate[5];
typedef enum Stickstate{used,nused};
Stickstate stickstate[5];
int stick[5];
int Ph[5];
int i,m;
void deadclock();
void ordered_allocation_philosopher();
void pre_allocation_philosopher();
void pre_hungry();
void quit();
void take();
int main(int argc,char*argv[])
{
int a;
x:
cout<<"\n\n\n\n"
"\t\t\t@*******哲学家死锁问题*************@\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 请选择操作(1-5) $\n"
"\t\t\t$__________________________________$\n"
"\t\t\t$ 1--死锁现象演示 $\n"
"\t\t\t$ 2--按序分配法防止死锁 $\n"
"\t\t\t$ 3--预分配法防止死锁 $\n"
"\t\t\t$ 4--防止饿死现象演示 $\n"
"\t\t\t$ 5--退出系统 $\n"
"\t\t\t$----------------------------------$\n"
"\t\t\t@**********************************@\n"<<endl;
cin>>a;
switch (a){
case '1':
deadclock();break;
case '2':
ordered_allocation_philosopher();break;
case '3':
pre_allocation_philosopher();break;
case '4':
pre_hungry();break;
case '5':
quit();break;
default:
goto x;
}
system("pause");
}
void take()
{
cout<<"申请左边筷子"<<endl;
if(stickstate[i] == nused)
{
stickstate[i] == used;
cout<<"拿起左边筷子"<<endl;
}
cout<<"申请右边筷子"<<endl;
if(stickstate[i-1] == nused)
{
stickstate[i-1] == used;
cout<<"拿起右边筷子"<<endl;
}
}
void deadclock()
{
for(i=0;i<5;i++)
{
if(i%2 == 0)
{
phstate[i] == thinking;
stickstate[i] == nused;
{
cout<<"第"<<i<<"位哲学家处于思想状态"<<endl;
}
}
else
{
phstate[i] == waiting;
stickstate[i] == nused;
cout<<"第"<<i<<"位哲学家处于等待状态"<<endl;
take();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询