/* Calculates the charge for a parking garage. The final amount depends
 * on the length of stay at the garage and on whether the driver is an 
 * already existing customer. 
 *
 * Author: V. Doufexi.
 * Date: October 30, 2017.
 */

#include<stdio.h>

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

	const int SHORT_TIME = 2, LONG_TIME = 24;
	const double SHORT_STAY_CHARGE = 2.5, 
				MEDIUM_STAY_CHARGE = 1.4, 
				LONG_STAY_CHARGE = 0.75; /* all amounts in euro/hr */
	const double EXTRA_DISCOUNT = 0.15;  /* for existing customers */
	char is_old_customer;
	double charge, discount = 0;
	int duration;

	printf("Time: ");
	scanf("%d", &duration);

	printf("Old Customer: ");
	scanf(" %c", &is_old_customer);
	
	if (duration <= SHORT_TIME) {
		charge = SHORT_STAY_CHARGE * duration;
	}
	else if (duration < LONG_TIME) {
		charge = MEDIUM_STAY_CHARGE * duration;
	}
	else {
		charge = LONG_STAY_CHARGE * duration;
	}

	if (is_old_customer == 'y' || is_old_customer == 'Y') {
		discount = charge * EXTRA_DISCOUNT;
		charge -= discount;
	}

	printf("\nTime: %2d hours\nDiscount: %.2lf\nCost: %.2lf\n", 
		duration, discount, charge);

	return 0;
}
