发新话题
打印

写个了小程序但在linux下编译老是出错?/请教呀

写个了小程序但在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
请高手指点!!      

TOP

#include <iostream.h>* p% c# k8 H6 G) J( P
( n+ Q8 P0 o/ {% N; S: p
#include <iomanip.h>
, h- b5 z. d0 q1 G, r8 ~9 P* ]* Q0 a0 Z
void pr_scores(float scores[ ]); //the prototype/ u/ v8 D2 d+ J1 v# h
void calr_average(float acerage,float *scores,char s_name[ ]);, C. _( V5 s0 M7 `

2 @' q6 d4 @; D2 Iint main ( )& _, }; Y9 m/ ^, l6 J9 H  ~, d
{
5 T: J, T; d& t( Y, j+ Y
! K9 _& m5 i3 B; H# F. E/ `+ `; M' ichar s_name[ ] ="Tri star University";
- x' P) Q5 j3 M' A, f* i% w4 ^+ E7 m/ x0 |
float scores[6] = {54.6,48.6, 36.6,66.6,72.6, 78.6};
7 x1 D1 q" ]0 k. n1 [2 Z
0 _" R/ w& z8 n# h& u% m7 Nfloat average =0.0;
7 t8 z" C' B4 r) {) `
) n9 y" Z3 j1 k/ G// call all function to print array.; y+ |$ z2 Z* Q' I* e

$ c0 N7 \7 N& w; d! ?) k9 h4 z
! ~3 S8 r9 D2 L* B! k% `
6 q) _# z% I( I  r0 F) p* c0 _/ tpr_scores(scores);
) @3 _1 O4 v, W) U$ ]1 K, d$ r' Q: Q' G( z, H
calr_average(average,scores, s_name);6 P+ c+ n; V/ @- z3 M) i5 P$ S! u
3 b0 `) H5 ?6 X$ x. H" `# X
( u; e/ G& `5 v. f  B0 r( a" G; y

& u5 D! R+ z( `return 0;
' f2 `" l8 O( ~! P4 l; u
4 [; T! z" z- j2 ?: C  ]) ~9 ?: w}
( k) s9 a4 Y( a. ~# g5 p) P8 {8 I0 J  N, {. P
2 R. T0 }' f$ @
2 [5 a. v7 C5 k! H- ^( L3 f9 w3 T
//the frist portotype.
$ R  }" E) ]8 Z" d7 V7 b9 L% ]$ i+ v/ z0 ?5 x

; \9 P0 z4 E' x4 o( m( p' h+ c: X
. ^! \' b! ^% V6 r# Ivoid pr_scores (float scores[6])# K% a: T# ^: z8 v# l, s
6 N6 p4 j$ p( e/ u0 t

! c& `! o. F( O4 D' m3 f9 I
1 Z+ A, c' a; F* P4 w9 v3 W{
6 D: ?& j- t+ `; l+ S, s( X$ y2 A& n% X- Q2 P5 M2 H
9 u# `& f& E# i3 R- K$ J& e

! v) {, h  `+ t! H* J4 Pint ctr;
% V3 H; {8 N+ U& s: {, n  k2 D
8 N9 l1 |9 `# Y3 T- Hcout << "Here are your scores: ";
; k/ I9 m. O  @, i6 v- J& Y* B3 K6 _
        for (ctr=0;ctr<6; ctr++)& U; b6 {6 ?: J
                cout << setprecision(2) << scores[ctr] <<"\n";
/ c9 W* r% a6 ~) f
: Y' T- p. n# V5 m/ I  W: B2 e: m* }! n4 k1 w+ [0 y4 [

; ?5 @# S9 P( p, _0 L. Areturn;
; G  w! \: c2 z, {/ p  I
& L% ^# W& [8 Z}9 A$ [' `( S$ k+ L- E: q7 E

0 ^  }9 J1 r! }+ k//the secend prototype.4 d3 \  j( s( T8 p" ]; u9 T

1 R) j4 u' l1 V! v
' D3 @, o3 L( ^" Z9 L6 k& f  R3 j1 ^: v+ c, ~& G# P2 {
void calr_average (float average,float scores[6], char s_name[ ])
: B9 ?# `: P: N8 d! J
; J. S) a4 R! R2 J" N' T{
' P' F# I- a5 y0 }  C7 e
. Y0 x4 A7 y# e) t9 T" w/ i/ H- ^7 \6 L7 d
- t& e+ }3 F+ S
int ctr;
2 s$ v/ m. s5 S: w" ?2 t/ m
2 M( b- n" s, }$ |0 A% Y( gfor (ctr=0;ctr< 6;ctr++)3 O  X; K6 I3 h8 ?

( x4 e4 ^5 W9 o' q( P( ?{6 x7 n6 U( r' g7 ?
' N7 w! W* g9 e8 G! r) [/ R/ F$ U
average += scores[ctr];3 C# u) S5 }4 a3 k# D% v' o. Y4 c
$ a0 U; `" W. W4 I1 R
}& W; p) @/ ]$ U  {
7 ?( j. d2 z& E2 a& q* f$ x; m
//computer the average;" o) u0 L6 g+ j* m+ s; o
& A; z! W/ j* }. Q( a; s7 Q
( Y1 S6 C6 v$ k; f! G( r: K
. o9 l" T- n5 u8 N! F9 G. B
average /= float(6);$ ?' e! R3 m+ A1 B& I& g

5 A+ e" L& N9 W/ |$ M% r* |7 D- ^) K- g' K
  f0 N9 i4 [: j
cout << "At" <<s_name<<", your class average is "<< setprecision(2) << average;" g% X6 d" R  ?4 b
0 D$ j" C. {9 `) c

  P5 Z' H0 T( z9 `4 i0 W1 H9 f, `0 q1 B! f! l7 w8 C
return ;9 e, `! W% q) T' r- v& C

0 I4 \* ]& Z& _: l}      

TOP

还是不可以
0 j, S$ A9 y9 F1 z出现的错误提示更多
, j6 W2 U2 `+ X  q4 A郁闷      

TOP

将函数写义处的void calr_average (float average,float scores[6], char s_name[ ])2 r$ L8 ^# Q' T6 z- E4 i0 U7 w9 f- g, H) A
也改为void calr_average (float average,float *scores, char s_name[ ])- L. G  E; W+ F
void pr_scores (float scores[6])改为void pr_scores (float *scores)      

TOP

不会的,我已经调试通过的,且能够正确运行
- J) R# s; y7 X* x; t5 A看起来最大可能是环境不一样
+ H5 K9 r6 T, \6 S0 H#include <iostream.h>
5 g2 K% J: |5 {7 R7 i/ t: f#include <iomanip.h>9 k4 R/ p: ^/ Z4 Y1 x; `! ^

+ z6 f6 N5 l/ }# I* W* T! p* Lvoid pr_scores(float* scores); //the prototype7 c9 T6 K* [# X7 W5 L3 U+ t5 B5 S
void calr_average(float acerage,float *scores,char* s_name);0 j. h& m& f- y/ {* R: Y; m
+ o9 G5 r! |% U, I2 N9 g3 H
int main ( ): Q% G( u- M5 n5 ]
{" N5 i: o5 |1 {9 ^- A
        char s_name[ ] ="Tri star University";& t( ~; S. P1 r
        float scores[6] = {54.6,48.6, 36.6,66.6,72.6, 78.6};
! P+ u( K3 [# t$ o$ F, R, b        float average =0.0;
8 k2 C3 V, {3 c4 P$ W2 L        // call all function to print array.
: B, J1 y) S: O6 k: B* j) |( X        pr_scores(scores);
# ^. E9 B+ K# l0 L2 z$ M2 ?6 P        calr_average(average,scores, s_name);' j# ^6 {, O; [4 m! a6 d5 t% {
        return 0;( P. x5 J4 T; S& j7 l7 _; Q) K
}
! u- _7 A" I, w3 r$ M+ Z4 r4 R; m//the frist portotype.  {# P3 h" D/ S
void pr_scores (float *scores)
# A) ]0 n  }! H( n{$ ?1 D2 S% F  n  z# n% w7 A8 ]
        int ctr;
$ B4 y0 o; I6 F+ A8 ~$ l8 r        cout << "Here are your scores: ";$ t7 K5 R# }3 n
        for (ctr=0;ctr<6; ctr++)
/ W9 f3 N' l* f* }: P; r2 J# w  _) d" H                cout << setprecision(2) << scores[ctr] <<"\n";0 K5 o5 T; U. z2 ^5 j% j
        return;' W% A. t5 ]5 |- W3 c* H& s+ E
}2 Y0 F+ X" g$ n5 w9 ?) {
//the secend prototype.0 k4 J' C5 e$ S( r8 ^' ?
void calr_average (float average,float* scores, char *s_name)! @/ _. e; |& R2 b
{" e, e% g9 R6 f) R' _3 ?* r1 `
        int ctr;
+ \: o& L# O, ^# A) {9 o( k7 I+ I        for (ctr=0;ctr< 6;ctr++)
+ h9 z* R8 p  p1 s, `        {$ i' ~) t' x( `/ m
                average += scores[ctr];: m0 R1 n! D+ J% \  b9 X1 N' J5 U
        }: l4 }- C6 l( j, A) T
//computer the average;, s8 u% s3 i) v- s7 Y" N
        average /= float(6);( D7 u5 n1 |% n; ?' `+ P
        cout << "At" <<s_name<<", your class average is "<< setprecision(2) << average;, H( T: J2 E! }) L
        return ;
) U# R) F$ O2 z- _1 d}
3 e& I, s4 Q8 m! D1 Y///////////////////////////
" m9 m1 z0 g" ~Here are your scores: 55, V) @; N) m* n* C, `( @
49
+ x  H: b$ T# d! q/ y+ W  {" z37
6 U* a" N. @9 O) H! g- [675 w$ X0 C) Q! g6 Z/ v5 L- Z- v! }
73
* y5 y+ s# R# A: F% Q79
4 M# f3 r9 C1 F9 J8 J% CAtTri star University, your class average is 60      

TOP

发新话题