写个了小程序但在linux下编译老是出错?/请教呀
我写的程序如下(是在书上看的)
% F( o j" q7 G |
8 e$ y4 G+ D- w: y! L* S# include <iostream.h>+ i& W$ i/ Z3 o2 {- t
, H# h8 Z, b& ~' f3 i2 L& F# v! q, _ # include <iomanip.h>
! f( D# p# K, |' `! r; i; a M. X$ I
5 r4 v5 K3 C1 z# {- C$ P
) }8 s/ Z( f- W8 R4 O4 ? void pr_scores(float scores[ ]); //the prototype
9 W( O- P! H' H4 N0 q* x# \
; H: o. N( r; _1 F( \3 R void calr_average(float acerage,float scores,char s_name[ ]);3 q* l) t+ T- u4 ~' [2 {
+ T& ^$ K( M9 C4 J2 w
& d3 w* ^' ]: M, G$ O0 |
: U5 g* i6 x j+ c4 o9 B; E void main ( )
% y) m {# K3 O2 s! ]
+ d# H8 q3 m' o( P ! _6 \$ ?' I: V" E
/ c Y) }! Q/ p9 K5 p! o
{ 8 G, U2 ~ e& N, |7 ], U
( F4 b; ~4 g# U1 o% f0 ~ char s_name[ ] ="Tri star University";7 t$ N8 y) `* Z0 R e. Z- w
7 @/ w0 \' t k% n) L, m: Y' F8 K float scores[6] = {54.6,48.6, 36.6,66.6,72.6, 78.6};
Q5 A# j- ^" L' X* L, r6 C# Q j# v3 s' m) n$ k
float average =0.0;5 l: x" B0 Z" V6 l' |2 A
3 l7 r# h" |/ a9 J/ P: j& q
// call all function to print array.$ Z# [6 f+ ~2 q6 ]$ I( k/ z
) U. B; u) @) P$ W8 T; n5 g: | ; g2 j$ Z( e+ X" P& c9 R0 M+ Z$ Q
1 E' Q2 G; q$ x, e0 w' M$ d8 m
pr_scores(scores);
( ?+ |2 j% b5 f! l0 C
0 U: p' E6 C6 l% e calr_average(average,scores, s_name);: z, g2 o6 t3 D3 L9 ~$ n: }+ W
% W0 ^) y! ]/ y) b# m/ B5 Z ' Z2 W0 ^; N0 S3 |- `2 [
9 c0 X, W: q- d return;+ U4 _& f: N- V0 W+ F7 @0 l9 o/ Z$ X
+ `+ _+ M- O% p$ I8 `4 O" P2 R
}2 d3 M) b( ~% w& T* S+ S6 ?6 g' B
9 K7 U1 z& y) z/ m# D8 C, q* x( b: b - u2 m- c( q! _( k7 M! ]
) a) H/ c% a! e% R
//the frist portotype.
$ T# M7 k ^" W# M! \1 u. o: W0 q6 r) l" x }3 _1 Q
( e$ l. q9 q7 A6 z% E
7 C! ?/ e8 T1 w9 I' O C0 d! c
void pr_scores (float scores[6])! G+ P, y% J: `
5 H7 s, s. T( | x% V. `- D/ l" q x
6 ?7 B, E: l8 X' O/ a& T# ]
6 D9 p0 A( R. ] D& f# w/ L {
4 c. q. a) z- x, {: g8 t4 y a6 I1 Y) [( \. J7 N7 T' D6 ^; x* n
( Y/ q l5 b4 L/ o
$ m! @4 e- K4 G$ R6 t) n int ctr;
% z( S' T, B) Q& {; W/ ~* }% b; r; ~* P1 ?' P
cout << "Here are your scores: ";$ \& \& ^5 G- H+ X
/ x( E3 S3 f. {* e1 U. ? for (ctr=0,ctr<6, ctr++)4 l7 O0 |1 H @ a6 W: \* t3 f2 E9 J1 E
# _# w( ]- ?# a% a2 o
# l$ b& }2 n1 V$ Y% q# Q2 [4 _8 Q U, ^1 e# j" L
cout << setprecision(2) << scores[ctr] <<"\n";
# ]: d, {3 r, ]4 Y1 @6 ^, B. a: k5 N
2 O& I: d$ V4 R3 ^$ q( s0 Z2 j+ c5 I6 m6 s
return;' B) f8 i7 S; M4 n6 |! r
4 Q4 ]" B" [+ z* V H# {* _3 |$ ?: ?( q; U
}
- V- ?* q1 o8 R4 j
) @" N2 a& D- A7 { I: t* ^; X //the secend prototype.. E6 |) q( Y/ T6 z0 ]& [: t0 v* k+ h
* I1 P E4 |5 U+ e
7 R$ j8 x8 K5 d* B7 y$ b! W4 T4 _+ E- r6 {9 j. p( \+ n0 I5 M8 H
void calr_average (float average,float scores[6], char s_name[ ]) R; C: e" E" t. Q# K
G g5 b" X, h+ o! x {
0 e; V' o$ O/ ?. }( Y
9 N E; I0 M. H* [7 T6 ~- ^) c % ?! Y: i+ X% J
% c; F1 R* ?" D% p int ctr;+ B' [1 Z T' r
0 [! e9 U. q {$ A: M
for (ctr=0;ctr< 6;ctr++)4 w8 @0 c: m' B4 o7 R3 G0 [8 ?
) i, e1 g. {5 B9 F, G
{& `2 H' r% E8 M9 Z
6 F' [( w3 ?9 G& @- w
average += scores[ctr];) Y8 d1 p4 ?6 P" i, @, x; Y5 g
( C3 G2 P+ E; O- b) z7 b, o
}
( a0 |" f6 X& F/ V2 a* U7 C0 ]: f( {; H3 e
//computer the average;
3 t& V! e! @& L( C- T
6 |1 R9 i* @7 }$ V 7 P2 m9 @; Q- n6 [
O/ e' @$ x3 ^6 Q: w7 j( j
average /= float(6);* l) @* r4 N- l3 ], ]( a
% e2 k1 ^# i. t: o# @ % x6 g+ V4 P, P: c n' x) O
T+ }7 G: L* o) s; A) ^9 j
cout << "At" <<s_name<<", your class average is "<< setprecision(2) << average;
# \* s1 G1 x6 z9 f0 D. Y+ W3 W% \4 p6 Q- M8 Q! v$ G* s
. _" F! l1 n- e5 z. r4 H7 I- Y5 q- b
% o4 y& B" `0 ]% N return ;
4 t! u( R7 H* ^/ ], g6 w& b
! l; W# d6 y0 j6 A" y3 i}% E- m3 @3 w. J( t$ V6 f. f) Q
! H: V& Y0 W. }
" R! T" Y* S- A$ t
: }0 e( Z+ w% ~( X9 r用:g++ -o xxxx xxxx.cpp 运行后的提示为
0 X) a: R" n7 `6 H P9 H
1 R+ O5 f, }* i. r, W2 A' w rmust return `int'
0 t7 O8 d1 E' y9 P+ jc++test.cpp: In function `int main(...)':3 N/ ^6 A! V2 g2 b
c++test.cpp:18: error: cannot convert `float*' to `float' for argument `2' to `void calr_average(float, float, char*)'
7 {, f/ Y- x% Y) b* Tc++test.cpp:20: error: return-statement with no value, in function returning 'int'
& y7 Z3 `( P- w0 X2 vc++test.cpp: In function `void pr_scores(float*)':
8 e- q8 R! T: \c++test.cpp:31: error: expected `;' before ')' token0 Y5 z% d& n% @) @( p
c++test.cpp:35: error: expected primary-expression before "return"4 a. F6 g% s {5 ?2 m& K' d1 q
c++test.cpp:35: error: expected `;' before "return"# Q3 R% a9 Y! x, o; Z; Z- b
c++test.cpp:35: error: expected primary-expression before "return". u9 ]2 e% [/ ]; ~
c++test.cpp:35: error: expected `)' before "return"
1 y3 r( ~. c4 t5 \& T: d7 ^9 F7 m6 a( I
- m8 {) z6 e( D
请高手指点!!