Lab 10/23 code

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define AMOUNT	20000.0
#define YEARS	10
#define RATE	10.0

typedef int BOOLEAN;

BOOLEAN inUnitCircle(double x, double y);
double random0to1(void);
double payment( double amount,
			    int numberOfPayments,
				double monthlyInterestRate );

void main(void) {

	int i;

	double x;
	double y;

	double monthlyPayment = payment(AMOUNT, YEARS*12, RATE / 12);

	//printf("payment for %f loan, %d years, %f%% APR is %f\n",
	//	         AMOUNT, YEARS, RATE,
	//			 monthlyPayment);

	for (i = 1; i <= 10; i++) {
		x = random0to1();
		y = random0to1();
		printf("(%f, %f) is%s in the circle\n", x, y,
			inUnitCircle(x, y) ? "" : " not");
	}

	return;
}

BOOLEAN inUnitCircle(double x, double y) {

	return (x*x + y*y < 1);
}

double random0to1(void) {

	return (1.0 * rand())/RAND_MAX;
}

double payment( double amount,
			    int numberOfPayments,
				double monthlyInterestRate ) {


	monthlyInterestRate = 1 + monthlyInterestRate / 100;

	return amount * (monthlyInterestRate - 1) /
		   (1 - pow(monthlyInterestRate, (double)-numberOfPayments));

}