/* Program that calculates income tax based on the following rates: 
 * Income up to 20000 ==> 22%
 * Income greater than 20000 ==> 35%
 * Additional discounts: -1% if there are children, -0.5% for good credit.
 *
 * Author: V. Doufexi
 * Date: Oct. 19, 2016
 */

#include<stdio.h>

#define LIMIT 20000
#define LOW_RATE 0.22
#define HIGH_RATE 0.35
#define CHILD_DISCOUNT 0.01
#define CREDIT_DISCOUNT 0.05

int main (int argc, char *argv[]) {

	double income, init_tax, final_tax, discount_rate;
	char kids_exist, credit_ok;

	printf("Income (Euro): ");
	scanf("%lf", &income);
	printf("Any kids? (y/n): ");
	scanf(" %c", &kids_exist);
	printf("Paid tax for last year? (y/n): ");
	scanf(" %c", &credit_ok);
	
	if (kids_exist == 'y' && credit_ok == 'y') {
		discount_rate = CHILD_DISCOUNT + CREDIT_DISCOUNT;
	}
	else if (kids_exist == 'y' && credit_ok == 'n') { 
		discount_rate = CHILD_DISCOUNT;
	}
	else if (credit_ok == 'y') { 
		discount_rate = CREDIT_DISCOUNT;
	}
	else {
		discount_rate = 0;
	}

	if (income <= LIMIT) {
		init_tax = income * LOW_RATE;	
	}
	else {
		init_tax = LIMIT * LOW_RATE + (income - LIMIT)*HIGH_RATE ; 
	}
	final_tax = init_tax - init_tax*discount_rate;
	
	printf("\nIncome: %.2lf\n", income);
	printf("Tax: %.2lf\n", final_tax);

	return 0;
}
