///////
//
// Student: Russell Lowke
//     T.F: Francis Crick
// Unit Four, pencil-and-paper - question 4 [worth 2pts],  7/10/2002
//
//  Given the time of day in terms of an hour, minute, second and
//  "day half" (i.e. AM or PM), write a function named fractionOfDay
//  to calculate and return the fraction of the day (type float) that
//  has elapsed since midnight
//


#include <iostream>
#include <iomanip>

bool const AM = false;
bool const PM = true;

float fractionOfDay(int hour, int minute, int second, bool dayHalf)
{
	int time;
	
	// convert midnight and midday to start of sequence
	if (hour == 12) {
		hour = 0;
	}
	
	// if PM then add 12 hours (1/2 a day)
	if (dayHalf == PM) {
		hour += 12;
	}
	
	// convert time to lowest common denominator (seconds)
	time = (hour*60*60) + (minute*60) + second;
	
	// return fraction of day
	return ( time / (float) (24*60*60) );
	
}
