/*******************************************************************************
FILE		OLA2.CC
COURSE		CSCI-1170-006
AUTHOR		Patrick Riley Connor
INSTRUCTOR	Jungson Yoo
DUE DATE	22 September 2009
DESCRIPTION	This program generates a billing statement based on user input,
		by use of a file for a hotel, accounting for various user needs.
INPUT		guestName	Guest's name			string
		roomNum		Guest's room number		int
		roomRate	Nightly cost of room		float
		nights		Number of nights stayed		int
		phoneCost	Phone costs incurred		float
		extraCost	Other costs incurred		float
OUTPUT		1. Purpose of the program.
		2. Prompts asking for user's information.
		3. Billing statement, with extra calculations given.
FORMULAS	roomCost = roomRate * nights		Total cost for the room
		roomTax = roomCost * tax;		The tax for room costs
		subTotal = roomCost + roomTax;		Before other costs
		grandTotal = subTotal + phoneCost + extraCost	Costs compiled
*******************************************************************************/

using namespace std;
#include <iostream>	// Needed for cout and cin
#include <fstream>	// Needed for managing our input file
#include <string>	// Needed for tracking our guest's name
#include <iomanip> 	// Needed for setprecision() and fixed

int main()
{
	ifstream	inFile;		// Stream for our input file.
	int		roomNum,	// Guest's room number.
			nights;		// Number of nights stayed.
	float		roomRate,	// Nightly cost for room.
			roomCost,	// Total cost for all nights stayed.
			roomTax,	// Tax charged on room costs.
			subTotal,	// Total on room and tax.
			phoneCost,	// Phone costs incurred.
			extraCost,	// Other costs incurred.
			grandTotal;	// Subtotal, phone, and other costs.
	string		guestName,	// Name of the guest.
			fileName;	// Input file name.
	const	float	tax = 0.0925;	// Sales tax.

	// State the purpose of our ever-so-benevolent program.
	cout 	<< 	"This program is used to generate a billing statement "
		<<	"for\nthe Murfreesboro Hotel Inc.\n";
		// Prompt the user for their name.
	cout	<<	"Please input the name of your file: ";
	cin 	>>	fileName;

	// Attempt to open up our file.
	inFile.open(fileName.c_str());

	// Read through our file and get the user's information.
	getline(inFile, guestName);		// Guest's name.
	inFile	>>	roomNum;		// Their room number.
	inFile	>>	nights;			// Number of nights stayed.
	inFile	>>	roomRate;		// Nightly cost of their room.
	inFile	>>	phoneCost;		// Their phone bill.
	inFile	>>	extraCost;		// And any extra costs acrued.

	if (inFile.fail())			// Check for any file errors.
	{
		// If we have any errors, inform the user...
		cout	<<	"The attempt to open your file failed, or your "
			<<	"file contained invalid data.\nPlease check "
			<<	"the input file for any possible errors.\n";
		return 1;			// and quit the program.
	}

	// Now that we have all of our user input, we can start making a few
	// calculations based on the user's input.

	roomCost = roomRate * nights;		// Total cost for the room.
	roomTax = roomCost * tax;		// The tax for room costs.
	subTotal = roomCost + roomTax;		// Subtotal before other costs.
	grandTotal = subTotal + phoneCost + extraCost;
					// Wrap all of our costs together.

	// Give ourselves a bit of room before we start feeding the user the
	// billing statement.
	cout	<<	endl	<<	endl	<<	endl	<<	endl

	// Set our output to truncate to 2 digits, as to satisfy normal rules of
	// using money.
		<<	fixed	<<	setprecision(2)

	// And now, the billing statement. Start pushing out all the information
	// requested. Note that we are still piggy-backing off of the cout
	// command located on line 86, as to avoid using fixed and setprecision
	// multiple times.
		<<	"Murfreesboro Hotel, Inc."		<<	endl
		<<	"-------------------------------------"	<<	endl
		<<	"Guest file:  "	<<	fileName	<<	endl
		<<	endl
		<<	"Guest name:  "	<<	guestName	<<	endl
		<<	"Room number: "	<<	roomNum		<<	endl
		<<	"Room rate:  $"	<<	roomRate	<<	endl
		<<	"Nights:      "	<<	nights		<<	endl
		<<	"Room cost:  $"	<<	roomCost	<<	endl

	// For this segment, format the tax so it looks in a pretty percentile
	// format rather than a decimal.
		<<	"Tax @ "	<<	tax * 100	<< "%: $"
		<<	roomTax		<<	endl

		<<	"Subtotal:   $"	<<	subTotal	<<	endl
		<<	"Phone bill: $"	<<	phoneCost	<<	endl
		<<	"Other bill: $"	<<	extraCost	<<	endl
		<<	"TOTAL:      $"	<<	grandTotal	<<	endl

	// A little bit more padding, to give room for the closing.
		<< 	endl	<<	endl

	// ...and a complimentary closing. Notice the closing semicolon, finally
	// finishing the cout command.
		<< 	"Thank you for staying with us at Murfreesboro"	<< endl
		<<	"Hotel. We hope you enjoyed your stay."		<< endl;

	// Woohoo! We're done!
	return 0;
}
