c++问题 : expected primary-expression before '[' token

帮帮忙吧,初学者,可这个程序总也编译不了
#include <stack>
#include <iostream>
using namespace std;
#define M 10
stack <int> stack1,stack2;

int way[M+6][M+31]=
{
{'0','0','1','1','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'1','0','1','0','0','0','0','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'0','0','1','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1','1'},
{'0','0','0','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','1'},
{'1','1','1','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','0','1'},
{'1','1','0','0','1','0','1','1','1','1','1','1','1','1','1','0','1','1','1','1','1','1','0','1','1','1','0','1','1','1','1','1','1','1','1','1','1','1','1','0','5'}
};

int judge(int line,int col)
{
if (line==5)
{
return 1;
}
else
{
cout<<"ok"<<endl;
if(!((line==M)&&(col==M)))
{
cout<<line<<endl;
cout<<col<<endl;
cout<<M<<endl;

if((way[line][col+1]==0)&&([col+1<31]))
{
cout<<"ok2"<<endl;
col++;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else
{
if((way[line+1][col]==0)&&([line+1<6]))
{
cout<<"ok3"<<endl;

line++;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else if
{
((way[line][col-1]==0)&&([col-1>-1]))
{
cout<<"ok4"<<endl;
col--;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else if
{
((way[line-1][col]==0)&&(line-1>-1))
{
cout<<"ok5"<<endl;

line--;
stack1.push(line);
stack2.push(col);

judge(line,col);
}
else
{
cout<<"ok6"<<endl;

line=stack1.top();
col=stack2.top();
stack1.pop();
stack2.pop();

judge(line,col);

}
}
}
}
}

}
}
void print()

int main()
{
int line,col;
int judge;

cout<<"please insert the line colum "<<endl;
cin>>line,col;
judge(line,col);
return 0;
}

return 0;
}
}

line 37 error: expected primary-expression before '[' token
line 48 error:expected primary-expression before '['
line 59 error: expected '(' before '{' token
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input
line 123 error: expected '}' at end of input

//修改编译错误的办法:
//所有提示expected primary-expression before '&' token;的地方
//都把ArrayList&删掉
//以及将i和j的赋值语句改为i=list1.elems;j=list2.elems;

#include
#include
using namespace std;

#define INIT_SIZE 100
#define INC_SIZE 10

//定义一个线性表
typedef struct
{
int *elems;
int len;
int size;
}ArrayList;

ArrayList list1, list2, list3;

//初始化线性表
void init(ArrayList&list)
{
list.elems=(int *)malloc(sizeof(int)*INIT_SIZE);
list.len=0;
list.size=INIT_SIZE;
}

//打印顺序表
void print(ArrayList& list)
{
for (int i = 0; i < list.len; i++)
{
cout<<list.elems[i]<<"\n";
}
}

//销毁顺序表
void destroy(ArrayList& list)
{
free(list.elems);
list.len = 0;
list.size = 0;
}

//向顺序表index位置插入元素

void insert(ArrayList&list,int index,int e)
{
if(list.len>=list.size)
list.elems=(int *)realloc(list.elems, sizeof(int) * (INC_SIZE + list.size));

for(int i=list.len-1;i>=index;i--)
{
list.elems[i+1]=list.elems[i];
}

list.elems[index] = e;
list.len++;
}

//向顺序表末尾插入元素e
void add(ArrayList& list, int e)
{
insert(list, list.len, e);
}

//删除顺序表index位置的元素
void remove(ArrayList&list,int index)
{
for(int i=index;i<=list.len-2;i++)
{
list.elems[i]=list.elems[i+1];
}
list.len--;
}

//将1,2比较然后放入3中的函数
void merge(ArrayList&list1,ArrayList& list2,ArrayList& list3)
{
init(list3);
int *i,*j;int k=0;
i=list1.elems;
j=list2.elems;

for(int s=1;s<=list1.len && s<=list2.len;s++,i++,j++)
if(*i<*j)
{
insert(list3,k++,*i);
}
else insert(list3,k++,*j);
}

void testBasic()
{

init(list1);
init(list2);
init(list3);
add(list1, 3);
add(list1, 7);
add(list2, 2);
add(list2, 4);
add(list2, 5);
merge(list1, list2, list3);
print(list3);
destroy(list1);destroy(list2);destroy(list3);
}

int main()
{
testBasic();
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-11
第一 大括号数量不对,多了;
第二 else if {
((way[line][col-1]==0)&&([col-1>-1]))
……
是什么意思,if 判断语句竟然放到大括号里面……,还有像这样 &&[col-1>-1] ,加个方括号是什么意思
第三 void print() 只写只一句是干嘛呢,既不是声明也没定义
第四 main函数结束后的语句 是做什么?本回答被网友采纳
第2个回答  2011-04-15
住只有在定义字符数组的时候才可以用字符串给字符数组赋值。还有一个拼写错误,我也改过来了
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int number(0);
double number1(0);
double number2(0);
struct Convert
{
char convert_name[100];
double convert_rate;
};
Convert convert[3] = ,0.125},,};
cout<<"choose a way to convert money"<<endl<<"1.yuan to dollar"<<endl<<"2.dollar to pound"<<endl<<"3.yuan to pound";
cin>>number;
cout<<"please enter the type that you want to convert";
cin>>number1;
if(number<3&&number>=0)
number2=number1*convert[number-1].convert_rate;
else
cout<<"sorry ,you entered a wrong number";
cout<<number1<<convert[number-1].convert_name<<" is "<<number2;

system("PAUSE");
return EXIT_SUCCESS;
}
另外,团IDC网上有许多产品团购,便宜有口碑
相似回答