[問題] 程式的改寫

看板C_and_CPP作者 (doggingg)時間15年前 (2011/02/10 16:25), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
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); 這題我的想法是: total=0; while(grade!=-1) { cin>>grade; total+=grade; } 不知道這樣有符合題目要求並且維持原意嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.208.81

02/10 16:34, , 1F
基本上沒什麼問題,不過要注意一下 grade的初值
02/10 16:34, 1F
文章代碼(AID): #1DKw48gu (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1DKw48gu (C_and_CPP)