Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll) git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| #include <stdio.h>
 | |
| #include "gm.h"
 | |
| void	getdec(char *,DEC *);
 | |
| void main(void);
 | |
| 
 | |
| void	main()
 | |
| {
 | |
| 	int	choice, opt, nper=0, diy=365;
 | |
| 	DECP	pv, intr, intamt;
 | |
| 	DEC	*p;
 | |
| 	
 | |
| 	printf("Simple interest computation\n");
 | |
| 	printf("Variable to solve for --\n");
 | |
| 	printf("  1)  Number of days\n  2)  Interest rate\n");
 | |
| 	printf("  3)  Principal\n  4)  Accrued interest\n");
 | |
| 	printf("Your choice:  ");
 | |
| 	scanf("%d", &choice);
 | |
| 	if (choice == 1)
 | |
| 		opt = GM_N;
 | |
| 	if (choice == 2)
 | |
| 		opt = GM_I;
 | |
| 	if (choice == 3)
 | |
| 		opt = GM_PV;
 | |
| 	if (choice == 4)
 | |
| 		opt = GM_INTR;
 | |
| 	
 | |
| 	if (opt != GM_N)  {
 | |
| 		printf("Number of days:  ");
 | |
| 		scanf("%d", &nper);
 | |
| 	}
 | |
| 	if (opt != GM_I)
 | |
| 		getdec("Percentage annual interest rate:  ", intr);
 | |
| 	if (opt != GM_PV)
 | |
| 		getdec("Principal:  ", pv);
 | |
| 	if (opt != GM_INTR)
 | |
| 		getdec("Accrued interest:  ", intamt);
 | |
| 	dprintf("Number of days in year (360 or 365):  ");
 | |
| 	dscanf("%d", &diy);
 | |
| 
 | |
| 	if (diy == 360)
 | |
| 		p = simp360(&nper, intr, pv, intamt, opt);
 | |
| 	else
 | |
| 		p = simp365(&nper, intr, pv, intamt, opt);
 | |
| 	
 | |
| 	if (opt==GM_N)
 | |
| 		dprintf("The result is %d\n",nper);
 | |
| 	else  {
 | |
| 		if (p)
 | |
| 			dprintf("The result is %v\n",p);
 | |
| 		else
 | |
| 			dprintf("Simple interest failed\n");
 | |
| 	}
 | |
| }
 | |
| 
 | |
| void	getdec(str, x)
 | |
| char	*str;
 | |
| DEC	*x;
 | |
| {
 | |
| 	int	i;
 | |
| 	
 | |
| 	do  {
 | |
| 		printf("%s", str);
 | |
| 		i = dscanf("%t", x);
 | |
| 	} while (i<1);
 | |
| }
 |