Re: [問題]有關for的問題

看板C_and_CPP (C/C++)作者 (永和汪小龍)時間16年前 (2009/12/28 20:49), 編輯推噓1(106)
留言7則, 4人參與, 最新討論串2/3 (看更多)
現在情況是 可以輸出使用者要求的數字個數 也可以輸出最小值 但卻無法列出使用者打出的所有數字 #include<iostream> using std::cout; using std::endl; using std::cin; int main() { int min; int number; int smallest; int smallestCounter; cout<<"please enter how many numbers you want to enter?"; cin>>number; for(smallestCounter=1; smallestCounter<=number; smallestCounter++) { cout<<"enter numbers you want to compare:"; cin>>smallest; if (smallest<min) min=smallest; } cout<<number<<" "; cout<<"\nmin= "<<min; system("pause"); return 0; } 最後是要輸出smallestCounter還是smallest啊? 還是...要輸出其他東西? 請問各位了 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 58.114.96.134

12/28 21:29, , 1F
你在for迴圈中要直接把你cin的smallest cout啊..@@
12/28 21:29, 1F

12/28 21:29, , 2F
不過為什麼要把輸入的東東叫作smallest..@@"
12/28 21:29, 2F

12/28 23:19, , 3F
不行 是要像我po的前一篇要求的那樣 謝謝!!
12/28 23:19, 3F

12/29 02:39, , 4F
想想可樂果...
12/29 02:39, 4F

12/29 04:15, , 5F
你可以先用陣列存起來, 最後再對陣列的所有數字做處理
12/29 04:15, 5F

12/29 04:16, , 6F
不要一個for就想做完所有事, 就像一個main寫完一樣
12/29 04:16, 6F

12/29 13:19, , 7F
你可以嘗試樓上的作法 在以這作法為基礎簡化成現在的作法
12/29 13:19, 7F
文章代碼(AID): #1BEAbkA5 (C_and_CPP)
文章代碼(AID): #1BEAbkA5 (C_and_CPP)