0
我在這裏是新來的,並試圖獲得有關學校工作的幫助。我需要這樣的代碼:在C++的重複結構中用while語句替換for語句
do //begin loop
{
cout << "Year " << years << ":" << endl;
for (double rate = .02; rate < .05; rate += .01)
{
balance = principal * pow(1 + rate, years);
//Display rate with zero decimal places
cout << fixed << set precision(0);
cout << " Rate " << rate * 100 << "%: $";
//Display balance with two decimal places
cout << setprecision(2) << balance << endl;
} //End for
//Update years counter
years += 1;
} while (years < 6);
從一個for語句轉到while語句。我遇到了一些問題,希望能夠對如何正確執行此操作有所瞭解。謝謝!
什麼特別的問題?你嘗試了什麼? –
你能解釋/顯示你試過的例子嗎?請閱讀此處,瞭解如何提出作業問題以及應該包括哪些內容以確保您能夠得到答案,而不僅僅是低調和忽略:) http://meta.stackexchange.com/questions/10811/how-do-i -ask-and-answer-homework-questions – Sk93
你知道'for'語句有3個部分嗎?你有沒有發現他們? while語句只有一個表達式,你應該知道'for'循環的三個部分中的哪一個對應於這個表達式。 – MSalters