看板 Grad-ProbAsk 關於我們 聯絡資訊
※ 引述《doggingg (doggingg)》之銘言: : Please rewrite the code segment shown below in a "while" statement : and a "for" statement in C++: : total=0; : do{ : cin>>grade; : if(grade!=-1) : total+=grade; : }while(grade!=-1); : 抱歉,小弟不是資工系的,之前沒念過程式,請問這題該怎麼寫? 題目是要改成用while跟用for來寫吧 while的: total=0; cin>>grade; while(grade!=-1){ total+=grade; cin>>grade; } ======================================= for的: cin>>grade; for(total=0;grade!=-1;){ total+=grade; cin>>grade; } ======================================= 我的話會這樣寫 不知道有沒有什麼問題@@" -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.112.87.10
charliejack:推~ 02/09 18:54