📄 subject_26714.htm
字号:
<p>
序号:26714 发表者:heavenkiller 发表日期:2003-01-04 10:23:40
<br>主题:help:error C2143: syntax error : missing ';' before '{'
<br>内容:这个程序在编译时出现了错误,但我实在不知道怎么消除这个错误,敬请各位高手赐教!<BR><BR>#include <iostream.h><BR>const int MAX=5;<BR>int findmax(int []);<BR><BR>int main()<BR>{<BR> int i,z;<BR> int nums[MAX]={2,18,1,27,16};<BR> cout <<"the maxnum value is "<<findmax(nums)<<nums[findmax(nums)]<<endl;<BR><BR> for (i=0;i<MAX;i++)<BR> {<BR> cout <<nums[i]<<" "<<endl;<BR> }<BR> return 0;<BR>}<BR><BR> //relization of function<BR><BR> int findmax(int vals[])<BR> {<BR> int i;<BR> int max=vals[0];<BR> for (i=1;i<MAX;i++)<BR> {<BR> if (max<vals[i])<BR> max=vals[i];<BR> }<BR> vals[MAX]={1,2,3,4,5};<BR> return max;<BR> }<BR><BR>以下是错误信息:<BR><BR>--------------------Configuration: find the max v01 - Win32 Debug--------------------<BR>Compiling...<BR>find the max v01.cpp<BR>E:\c++专区\find the max v01\find the max v01.cpp(7) : warning C4101: 'z' : unreferenced local variable<BR>E:\c++专区\find the max v01\find the max v01.cpp(29) : error C2059: syntax error : '{'<BR>E:\c++专区\find the max v01\find the max v01.cpp(29) : error C2143: syntax error : missing ';' before '{'<BR>E:\c++专区\find the max v01\find the max v01.cpp(29) : error C2143: syntax error : missing ';' before '}'<BR>Error executing cl.exe.<BR><BR>find the max v01.exe - 3 error(s), 1 warning(s)<BR><BR><BR><BR><BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:死循环 回复日期:2003-01-04 12:41:06
<br>内容:vals[MAX]={1,2,3,4,5};<BR>这一句编译怎么能通过?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:heavenkiller 回复日期:2003-01-04 12:55:15
<br>内容:为什么不能通过呢?<BR>你能说得具体一点吗?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-01-04 19:06:32
<br>内容:vals[MAX]={1,2,3,4,5}; 只有在定义数组时初始化使用,否则为错误。<BR><BR>如果非要赋值,可采用单循环给每个元素赋值
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -