//Charlotte Davies-Kiernan CS1A Chapter 6 P. 373 #14
//
/******************************************************************************
*
* Compute Patient's Hospital Charges
* ____________________________________________________________________________
* This program determines a patient's charges for their hospital stay
* depending on whether they are an in-patient or an out-patient.
*
* Formulas used:
* In-Patient:
* totalCharges = (days * dailyRate) + medication + services
* Out-Patient:
* totalCharges = medication + services
* ____________________________________________________________________________
* Input
* patientType //Whether the patient was in or out of the hospital
* days //Amount of days the patient spent in the hospital
* dailyRate //Rate of stay for patient in the hospital
* medication //Price of medication given/taken by patient
* services //Price of services (labs, etc.)
* Output
* totalCharges //Total amount charged for the patients hospital experience
*****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Function Prototypes
float calculate_in_charges(int days, float dailyRate, float medication, float services);
float calculate_out_charges(float medication, float services);
int main() {
//Data Dictionary
char patientType; //INPUT - Whether the patient was an in or out patient
int days; //INPUT - Amount of days the patient spent in the hospital
float dailyRate; //INPUT - Rate of stay for patient in the hospital
float medication; //INPUT - Price of medication given/taken by patient
float services; //INPUT - Price of services (labs, etc.)
float totalCharges; //OUTPUT - Total amount charged for the patients hospital experience
cout << fixed << setprecision(2);
cout << "Was the patient an In-Patient or an Out-patient? (I/O): " << endl;
cin >> patientType;
//Validate Input
while (patientType != 'I' && patientType != 'O'){
cout << "Invalid input. Please enter 'I' for In-Patient or 'O' for Out-Patient: ";
cin >> patientType;
}
//In-Patient Path
if (patientType == 'I'){
cout << "In-Patient Information: " << endl;
cout << "Enter number of days spent in the hospital: " << endl;
cin >> days;
if (days < 0){
cout << "Please enter a non negative number: " << endl;
cin >> days;
}
cout << "Enter daily rate: $" << endl;
cin >> dailyRate;
if (dailyRate < 0){
cout << "Invalid input, please enter a non negative number: " << endl;
cin >> dailyRate;
}
cout << "Enter hospital medication charges: $" << endl;
cin >> medication;
if (medication < 0){
cout << "Invalid input, please enter a non negative number: " << endl;
cin >> medication;
}
cout << "Enter charges for hospital services (lab tests, etc.): $" << endl;
cin >> services;
if (services < 0){
cout << "Invalid input, please enter a non negative number: " << endl;
cin >> services;
}
totalCharges = calculate_in_charges(days, dailyRate, medication, services);
}
//Out-Patient Path
else {
cout << "Out-Patient Information: " << endl;
cout << "Enter hospital medication charges: $" << endl;
cin >> medication;
if (medication < 0){
cout << "Invalid input, please enter a non negtaive number: $" << endl;
cin >> medication;}
else{
cout << "Enter charges for hospital services (lab tests, etc.): $" << endl;
cin >> services;}
if (services < 0){
cout << "Invalid input, please enter a non negative number: $" << endl;
cin >> services;}
totalCharges = calculate_out_charges (medication, services);
}
//Display Total
cout << "Total Hospital Charges: $" << totalCharges << endl;
return 0;
}
//In-Patient Function
float calculate_in_charges(int days, float dailyRate, float medication, float services)
{
return (days * dailyRate) + medication + services;
}
//Out-Patient Function
float calculate_out_charges(float medication, float services)
{
return medication + services;
}