Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[°ÝÃD]coutªººÃ°Ý....

0 views
Skip to first unread message

愛與願違

unread,
May 7, 2002, 4:04:21 PM5/7/02
to
各位大哥,以下是小弟寫的一個作業.....
輸出結果如下:
Please enter a mark: 22
Please enter a mark: 28
Please enter a mark: 30
Please enter a mark: 17
Please enter a mark: 25
Please enter a mark: 10
Please enter a mark: 29
Please enter a mark: 27

The average of 22 28 30 17 25 10 29 27 is 23.5

結果是正確的,但我對我寫的一個地方有個疑問.....請往下看

#include <iostream.h>

float output (int direct) ;

const int count = 8 ;
float athletes_number[count] ;

int main()
{
output (0) ;

cout << endl << "The average of " ;
cout << "is " << output (1) << endl ;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
為什麼22 28 30 17 25 10 29 27這段結果會輸出在is前面,而23.5則在is之後?
這段敘述是小弟陰錯陽差中寫出來的,想了好久仍想不出所以然
請各位大哥幫忙解一下疑惑,
並請評論一下,如果這樣寫可行,那是一種'好的'寫法嗎?
謝謝!!

return 0 ;
}

float output (int direct)
{
float average = 0 ;

for (int number = 0 ; number < 8 ; number++)
{
if (direct == 0)
{
cout << "Please enter a mark " << ": " ;
cin >> athletes_number[number] ;
}
else if (direct == 1)
{
cout << athletes_number[number] << " " ;

average += athletes_number[number] ;
}
}
average /= 8 ;
return average ;
}
--
[1;32m※ Origin: [33m碩誠 Linux 資訊站 [37m<bbs.sayya.org> [m
[1;31m◆ From: [36m166-253.kingnet.net.tw [m

十二秒的轟殺

unread,
May 8, 2002, 2:05:21 AM5/8/02
to
: #include <iostream.h>

: float output (int direct) ;
: const int count = 8 ;
: float athletes_number[count] ;
: int main()
: {
: output (0) ;
^^^^^^^^^^^^^^^^^^
這行作用應該是input吧… @@?
建議多寫一個input()…可讀性會比較好
: cout << endl << "The average of " ;

: cout << "is " << output (1) << endl ;
: }

--
俺奧手見!!
..
!
秘劍.亂舞太刀!!

--
[m [1;33;46m〒作者:Blueshine 來自:226082.D17-226.ncu.edu.tw [m
[1;36m◎二進位的世界 [37m【140.115.50.50‧binary.csie.ncu.edu.tw

0 new messages