void fanxiang()
{
float money;
float base;
double total = 1.0f;
int day;
int x;
int k;
char lab;
double total1;
printf("-------------------------------------------------------------|\n");
printf("請輸入你需要得到的金額:\n");
scanf("%f",&money);
while(money<=0)
{
printf("-------------------------------------------------------------|\n");
printf("輸入值為負數,請重新輸入:\n");
scanf("%f",&money);
}
printf("-------------------------------------------------------------|\n");
printf("請輸入平均年回報率:\n");
scanf("%f",&base);
while(base<=0)
{
printf("-------------------------------------------------------------|\n");
printf("輸入值為負數,請重新輸入:\n");
scanf("%f",&base);
}
printf("-------------------------------------------------------------|\n");
printf("請輸入存入的年數\n");
scanf("%d",&day);
while(day<=0)
{
printf("-------------------------------------------------------------|\n");
printf("輸入值為負數,請重新輸入:\n");
scanf("%d",&day);
}
printf("-------------------------------------------------------------|\n");
lab:printf("若是複利選擇1,單利選擇2\n");
scanf("%d",&x);
printf("-------------------------------------------------------------|\n");
if(x==1)
{
printf("請輸入複利次數:\n");
scanf("%d",&k);
while(k<=0)
{
printf("-------------------------------------------------------------|\n");
printf("輸入值為負數,請重新輸入:\n");
scanf("%d",&k);
}
printf("-------------------------------------------------------------|\n");
total=total*pow(1+base/k,k*day);
total1=money/total;
printf("需要的本金為:%f\n",total1);
printf("-------------------------------------------------------------|\n");
}
else if(x==2)
{
total=base*day;
total1=money/(1+total);
printf("需要的本金為:%f\n",total1);
printf("-------------------------------------------------------------|\n");
}
else
{
printf("請重新輸入1或者2\n");
goto lab;
}
}
目前這是我複利計算中其中一個函數方法,下面将對其進行單元測試
測試子產品 | 測試輸入 | 預期結果 | 實際結果 | 蟑螂追蹤 |
計算本金子產品 | 終金,年回報率,存入年數,選擇存款方式,(複利情況有次數) | 本金值 | ||
測試複利運算結果 | 100000,0.03,5,1,3 | 86134.947769 | 符合 | |
測試終金為負值 | -100000,0.03,5,1,3 | 提示終金重新輸入 | ||
測試年回報率為負值 | -100000,0.03,5,1,3 | 提示年回報率重新輸入 | ||
測試存入年數為負值 | 100000,0.03,-5,1,3 | 提示存入年數重新輸入 | ||
測試存款方式輸入除1和2的值 | 100000,0.03,-5,5 | 提示存款方式重新輸入 | ||
測試單利運算結果 | 100000,0.03,5,2 | 86956.521993 | ||
測試輸入字母 | a,0.03,5,2 | 提示輸入錯誤請重新輸入數字 | 不符合,其出現無限循環 | |
測試輸入為0 | 0,0.03,5,2 | 提示重新輸入 | ||
測試輸入數字過大 | 9999999999999,0.03,5,2 | 提示數字過大請重新輸入 | 不符合,本金出現8695652049671.691400 | |
測試輸入年為小數 | 100000,0.03,1.5,2 | 程式可以繼續運作 | 不符合,出現無限循環 | |
測試輸入利率為0 | 100000,0,5,2 | 提示請重新輸入 | ||
測試輸入複利情況下複利次數為負數 | 100000,0.03,5,1,-3 | |||
...... |
目前已經進行BUG的查出,以後将會對BUG來進行修改。