// hotel.c hotel management functions
#include <stdio.h>
#include <stdbool.h>
#include "hotel.h"

int menu(void)
{
	int code, status;
		
	printf("\n%s%s\n", STARS, STARS);
	printf("Enter the number of the desired hotel:\n"
	       "1) Fairfield Arms\t\t2) Hotel Olympic\n"
	       "3) Chartworthy Plaza\t\t4) The Stockton\n"
	       "5) quit\n");
	printf("\n%s%s\n", STARS, STARS);
	
	code = get_int();
	
	/*	
	while ((status = scanf("%d", &code)) != 1)
	{
		if (status != 1)
			scanf("%*s");
		printf("Enter an integer from 1 to 5, please. ");
	}
	*/
	
	return code;
}

int getnights(void)
{
	int nights;
	
	printf("How many nights are needed? ");
	nights = get_int();
	
	/*
	while (scanf("%d", &nights) != 1)
	{
		scanf("%*s");
		printf("Please enter an integer such as 2. ");
	}
	*/
	return nights;
}

void showprice(double rate, int nights)
{
	int n;
	double total = 0.0;
	double factor = 1.0;
	
	for (n = 1; n <= nights; factor *= DISCOUNT)
		total += rate * factor;
	printf("The total cost will be $%0.2f.\n", total);
}

int get_int(void)
{
	int input;
	char ch;
	
	while (scanf("%d", &input) != 1)
	{
		while ((ch = getchar()) != '\n')
			// dispose of bad input
			putchar(ch);
		printf(" is not an integer.\n"
		       "Please enter an integer value, such as 25, -178, "
		       "or 3: ");
	}
	return input;
}
