[問題] 條件式判斷

看板C_and_CPP作者 (doggingg)時間13年前 (2011/02/10 19:21), 編輯推噓0(006)
留言6則, 4人參與, 最新討論串1/8 (看更多)
There are 4 tests for 10 students with grade ranges as: A:(grade>=90) B:(90>grade>=80) C:(80>grade>=70) D:(70>grade>=60) E:(grade<60) write a nested loop to count the number of grades, eg. 10'A's , 15'B's,etc and put the results into sc[5] (you can not use if statement) 題目是說10個同學每人有四個成績共40個成績,計算A等級幾個,B等級幾個 把這五個等級的個數放進sc陣列中, 我想請教的是,不用if寫,要怎麼寫,是用switch嗎? 還是?: -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.208.78

02/10 19:24, , 1F
?:應該可以. 不過如果grade是整數然後input都合法的話我
02/10 19:24, 1F

02/10 19:25, , 2F
倒是有噁心的作法.
02/10 19:25, 2F

02/10 19:35, , 3F
switch 不行嗎
02/10 19:35, 3F

02/10 19:46, , 4F
只有5個if-else 而已,為何要強調不用 if-else 呢?
02/10 19:46, 4F

02/10 19:47, , 5F
如果是非常多個if-else的話(#1B-JvmyF)再考慮其它方法
02/10 19:47, 5F

02/10 19:59, , 6F
也有不噁心的作法 ^.<
02/10 19:59, 6F
文章代碼(AID): #1DKyfADN (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1DKyfADN (C_and_CPP)