最悲觀假設:房價 200 萬年增 10%,軟工年薪固定 40 萬,不吃不喝全存,無投資報酬。每年存款增加 40 萬,房價乘 1.1。模擬發現存款永遠追不上房價(100 年內不可買),印出悲劇結果。
#include <stdio.h>
int main() {
int i=0, flag=0;
float salary=40, house=200, rate=0.1, savings=0;
house = house * (1+rate); // 第1年底房價
while (salary * i < house) { // 這裡邏輯有誤,應累積薪資
i++;
house += house * rate; // 房價複利
if (i > 100) { flag=0; break; }
}
if (flag) printf("%d年後可買房\n", i);
else printf("工作一輩子也買不起房!\n");
return 0;
}

原碼條件 salary * i < house 錯誤,應為累積變數 savings += salary。修正後仍發現:固定薪資 vs 複利房價,存款增長為等差數列,房價為等比數列,長期必敗。
float savings = 0;
while (savings < house) {
savings += salary;
house *= 1.1;
i++;
}