//Andres Guzman CSC5 Chapter 6, P. 373, #14
//
/*******************************************************************************
*
* CALCULATE HOSPITAL BILL
* ______________________________________________________________________________
* This program will calculate the total bill of a hospital as either a in or out
* patient
*
* Computation:
*
* total = (day * rate) + charges + services, total = charges + services
* ______________________________________________________________________________
* INPUT
*
* answer = allows user to input either in or out
* days = Number of days spent in hospital
* rate = charge of stay per day
* charges = cost of medications
* services = cost of hospital services
*
* OUTPUT
* total = All charges added up for in and out patient
*******************************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
double patient(string In); //overloaded function prototype
double patient(string Out); //overloaded funcntion prototype
int main()
{
string answer; //Holds string input for user to enter in or out
cout << "Was the Patient admitted as an In-Patient or Out-Patient? ";
cin >> answer;
cout << endl;
//Creating while loop for input validation
while (answer != "In" && answer != "Out" && answer != "out"
&& answer != "in" && answer != "IN" && answer != "OUT") //Allows only
//either in or
//out input.
{
cout << "Invalid Patient Type." << endl;
cout << "Was the Patient admitted as an In-Patient or Out-Patient? ";
cin >> answer;
cout << endl;
}
//
//Creates if statement In Patient Function
if (answer == "in" || answer == "In" || answer == "IN") //Validates input
{
patient("In"); //In Patient Function
}
//
//Creates if statement for Out Patient Function
if (answer == "out" || answer == "Out" || answer == "OUT")//Validates input
{
patient("Out"); //Out Patient Function
}
return 0;
}
/*******************************************************************************
* Definition of function patient. The "In" is meant to hold variables day,
* rate, charges, and services, to differentiate the overloaded
* function.
******************************************************************************/
double patient()
{
//
//Initializing Variables
double days; //Days in hospital
double rate; //Cost per day in hospital
double charges; //Cost of medications
double services;//Cost of hospital services like xrays
//
//Displaying prompt
cout << "Days Spent in Hospital: ";
cin >> days;
//
//Creates input validation for days
while (days < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Days Spent in Hospital: ";
cin >> days;
}
cout << "\nDaily Rate: ";
cin >> rate;
//
//Creates input validation for rate
while (rate < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Daily Rate: ";
cin >> rate;
}
cout << "\nMedicaion Charges: ";
cin >> charges;
//
//Creates input validation for charges
while (charges < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Medication Charges: ";
cin >> charges;
}
cout << "\nHospital Services: ";
cin >> services;
//
//Creates input validation for services
while (services < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Hospital Services: ";
cin >> services;
}
//
//Computes total cost of hospital
double total = (days * rate) + charges + services; //Adds all the charges
//
//Outputs results
cout << fixed << setprecision(2) << "\nTotal Charges: " << total;
return total;
}
/*******************************************************************************
* Definition of function patient. The "Out" is meant to hold variables charges
* and services, to differentiate the overloaded function.
******************************************************************************/
double patient(string Out)
{
//
//Initializing Variables
double charges; //Charges for medication
double services;//Hospital services charges
//
//Display promt
cout << "Medicaion Charges: ";
cin >> charges;
//
//Creating while loop for input validation
while (charges < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Medication Charges: ";
cin >> charges;
}
cout << "\nHospital Services: ";
cin >> services;
//
//Creating while loop for input validation
while (services < 0)
{
cout << "Invalid Input. Please Enter a Valid Amount" << endl;
cout << "Hospital Services: ";
cin >> services;
}
//
//Computes Out patient total
double total = charges + services; //Adds all charges
//
//Output Results
cout << fixed << setprecision(2) <<"\nTotal Charges: " << total;
return total;
}