#include <stdio.h> #include <math.h> void List (); void A (); void B (); void C (); void D (); void E (); void F (); void G (); Main () {int sel; while (1) {List (); printf ("\ t Please select:"); while (scanf ("%d", &sel)!=1| | sel<0| | SEL>7)//prevents the input of a character and the input number is not an integer 0-7 {printf ("\ t input error!!! \n\n\t Please re-select: "); while (GetChar ()! = ' \ n '); Handle Enter} if (sel==0) {printf ("\ t welcome next use, thank you!\n"); Break } switch (SEL) {//select 1~7 function Case 1:a (); Break Case 2:b (); Break Case 3:c (); Break Case 4:d (); Break Case 5:e (); Break Case 6:f (); Break Case 7:g (); Break }}}} void list ()//directory Table {printf ("\t|--------------------------------------|\n"); printf ("\t| function |\n "); printf ("\t|--------------------------------------|\n"); printf ("\t| |\n "); printf ("\t| 1. Compounding (one payment) |\n "); printf ("\t| 2. Compounding (multiple equal payments) |\n "); printf ("\t| 3. Simple interest |\n "); printf ("\t| 4. Investment funds |\n "); printf ("\t| 5. Input time |\n "); printf ("\t| 6. Interest rate |\n "); printf ("\t| 7. Monthly matching principal and interest repayment |\n "); printf ("\t| 0. Exit |\n "); printf ("\t| |\n "); printf ("\t|--------------------------------------|\n"); } void A ()//once put compounding {int n;//time n double p,i,sum1;//total amount p, interest rate I, Benli and sum1 printf ("\n\t* Please enter deposit amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the deposit amount: "); GetChar (); } printf ("\t* Please enter interest rate:"); while (scanf ("%lf", &Amp;i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter storage time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage time (year): "); GetChar (); } ; Sum1=p*pow ((1+i), n);//compound Interest Calculation formula printf ("\t** Benli and for:%.2lf\n\n", sum1);//output compounding results} void B ()//multiple equal pay compound interest (int n); Double p,i,sum2=0; Char choose; printf ("\n\t Multiple Equal Input method: \n\t1. Multiple month \n\t2. Equal number of multiple years to vote \n\t* Please select:"); while (scanf ("%d", &choose)!=1| | choose<1| | CHOOSE>2) {printf ("\ t input error!!! \n\n\t Please re-select: "); while (GetChar ()! = ' \ n '); } while (GetChar ()! = ' \ n '); if (choose==1) {printf ("\n\t* Please enter the monthly investment amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the monthly investment amount: "); GetChar (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter storage time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter storage Time (years):"); GetChar (); } sum2=p*12* (Pow (1+i,n)-1)/i;printf ("\t** Benli and for:%.2lf\n\n", sum2); } else {printf ("\n\t* Please enter an annual investment amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the annual investment amount: "); GetChar (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter storage time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage time (year): "); GetChar (); }sum2= (P*pow ((1+i), N)-1)/i;printf ("\t** Benli and for:%.2lf\n\n", sum2); }} void C ()//simple interest evaluates {int n; Double p,i,sum3; printf ("\n\t* Please enter deposit amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the deposit amount: "); GetChar (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter storage time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage time (year): "); GetChar (); } sum3=p* (1+i*n); printf ("\t** Benli and for:%.2lf\n\n", sum3); } void D ()//input capital {int n; Double sum4,i,p;//p for input of the principal printf ("\n\t* Please enter Benli and:"); while (scanf ("%lf", &sum4)!=1| | sum4<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter Benli and: "); GetChar (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter deposit time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the deposit time (year): "); GetChar (); } p=sum4/(1+i*n); printf ("The principal invested by \t**:%.2lf\n\n", p); } void E ()//input time {double n; Double sum5,i,p; printf ("\n\t* Please enter storage amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage amount: "); GetChar (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } printf ("\t* Please enter thisLee and: "); while (scanf ("%lf", &SUM5)!=1| | sum5<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter Benli and: "); GetChar (); } n= (log (sum5/p))/(log (1+i)); printf ("\t** Input time:%.0lf\n\n", N); }void F ()//interest rate {double sum6,i,p,n; printf ("\n\t* Please enter storage amount:"); while (scanf ("%lf", &p)!=1| | p<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage amount: "); GetChar (); } printf ("\t* Please enter storage time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the storage time (year): "); GetChar (); } printf ("\t* Please enter Benli and:"); while (scanf ("%lf", &SUM6)!=1| | sum6<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter Benli and: "); GetChar (); } i=pow ((sum6/p), (1/n))-1; printf ("\t** interest Rate:%.2lf\n\n", i);} void G () {double sum7,i,p,n;printf ("\n\t* Please enter loan amount:"); while (scanf ("%lf", &sum7)!=1| | sum7<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter Benli and: "); GetChar (); } printf ("\t* Please enter loan time (years):"); while (scanf ("%d", &n)!=1| | n<=0| | n>100) {printf ("\ t input error!!! \n\n\t* Please re-enter the loan time (year): "); GeTCHAR (); } printf ("\t* Please enter annual interest rate:"); while (scanf ("%lf", &i)!=1| | i<=0) {printf ("\ t input error!!! \n\n\t* Please re-enter the interest rate: "); GetChar (); } p=sum7*i/(12* (1+i) * (POW (1+i,n)-1));p rintf ("\t** monthly equal and principal repayment:%.2lf\n\n", p);}
Compound interest Calculation (after modification)