⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_26714.htm

📁 vc
💻 HTM
字号:
<p>
序号:26714 发表者:heavenkiller 发表日期:2003-01-04 10:23:40
<br>主题:help:error C2143: syntax error : missing ';' before '{'
<br>内容:这个程序在编译时出现了错误,但我实在不知道怎么消除这个错误,敬请各位高手赐教!<BR><BR>#include &lt;iostream.h&gt;<BR>const int MAX=5;<BR>int findmax(int []);<BR><BR>int main()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;int i,z;<BR>&nbsp;&nbsp;&nbsp;&nbsp;int nums[MAX]={2,18,1,27,16};<BR>&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;"the maxnum value is "&lt;&lt;findmax(nums)&lt;&lt;nums[findmax(nums)]&lt;&lt;endl;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;for (i=0;i&lt;MAX;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout &lt;&lt;nums[i]&lt;&lt;"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"&lt;&lt;endl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;//relization of function<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;int findmax(int vals[])<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int i;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int max=vals[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (i=1;i&lt;MAX;i++)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (max&lt;vals[i])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;max=vals[i];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vals[MAX]={1,2,3,4,5};<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return max;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<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 + -