fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // 宣告變數
  6. int balance = 100;
  7. int r = 10;
  8. int goal = 200;
  9.  
  10. int n = 0;
  11. while (balance < goal) {
  12. balance *= (1 + r / 100.0);
  13. n++;
  14. }
  15.  
  16. cout << "Holding years = " << n << endl;
  17. cout << "Balance = " << balance << endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Holding years = 8
Balance = 212