#include <stdio.h>#include<math.h>voidList ();voidA ();voidB ();voidC (); main () {intsel; List (); printf ("\ t Please select:"); while(SCANF ("%d", &sel)! =1|| sel<1|| Sel>4)//prevents the input of a character and the number entered is not an integer 1~4{printf ("\n\t input Error, please re-enter:"); GetChar (); } while(GetChar ()! ='\ n');//Handle Enter while(1){//Exit System if(sel==4) printf ("\ t Welcome to use again next time, thank you!\n"); Break; } Switch(SEL) {//Select the function of 1~4 Case 1: A (); Break; Case 2: B (); Break; Case 3: C (); Break; }}voidList ()//Catalog Table{printf ("\t|--------------------------------------|\n"); printf ("\t| Catalogue |\n"); printf ("\t|--------------------------------------|\n"); printf ("\t| |\n"); printf ("\t| 1. Compounding |\n"); printf ("\t| 2. Simple Interest |\n"); printf ("\t| 3. Investment funds |\n"); printf ("\t| 4. Exit |\n"); printf ("\t| |\n"); printf ("\t|--------------------------------------|\n");}voidA ()//Compound Interest Calculation{ intN//Time N DoubleP,I,SUM1;//Total amount P, interest rate I, Benli and sum1printf"\n\t Please enter the total amount of the deposit:"); scanf ("%LF",&p); printf ("\ t Please enter the interest rate:"); scanf ("%LF",&i); printf ("\ t Please enter the time (year):"); scanf ("%d",&N); Sum1=p*pow ((1+i), n);//formula for compoundingprintf"\ t Benli and for:%.2lf\n", SUM1);//results of the output compounding calculation}voidB ()//Simple Interest Calculation{ intN; Doublep,i,sum2; printf ("\n\t Please enter the total amount of the deposit:"); scanf ("%LF",&p); printf ("\ t Please enter the interest rate:"); scanf ("%LF",&i); printf ("\ t Please enter the time (year):"); scanf ("%d",&N); Sum2=p* (1+i*N); printf ("\ t Benli and for:%.2lf\n", sum2);}voidC () {intN; DoubleSum3,i,p;//P is the principal of the investmentprintf"\n\t Please enter the total amount of the return:"); scanf ("%LF",&sum3); printf ("\ t Please enter the interest rate:"); scanf ("%LF",&i); printf ("\ t Please enter the time (year):"); scanf ("%d",&N); P=SUM3/(1+i*N); printf ("\ t invests the principal as:%.2lf\n", p);}
This program mainly implements 4 functions: 1. Compound interest calculation; 2. Simple interest calculation; 3. Investment; 4. Exit the system. The first three functions used three functions: A (); B (); C (). The method of implementation is probably the same, all through the input of relevant information, in the formula calculation. The main function, main (), uses the Swich () statement to select the function that invokes the function. When entering a non-1~4 integer, there is a reminder to "re-enter".
There are a lot of imperfections in this program, and I will continue to make it perfect ....
Compound Interest Calculation 2.0