#include <iostream>
using namespace std;
int readNotNegative() {
int x;
cin >> x;
while (x < 0) {
cout << "Please enter not negative data: ";
cin >> x;
}
return x;
}
int computeTotalCharges(int hospitalServices, int hospitalMedication) {
return hospitalMedication + hospitalServices;
}
int computeTotalCharges(int numberOfDays, int dailyRate, int hospitalServices, int hospitalMedication) {
return numberOfDays * dailyRate + hospitalMedication + hospitalServices;
}
int main() {
int patientType;
cout << "Enter 0 for in-patient or 1 for out-patient: ";
cin >> patientType;
while ((patientType != 0) && (patientType != 1)) {
cout << "Incorrect data! Enter 0 for in-patient or 1 for out-patient: ";
cin >> patientType;
}
int numberOfDays = 0;
int dailyRate = 0;
int hospitalServices = 0;
int hospitalMedication = 0;
if (patientType == 0) {
cout << "Enter number of days spent in the hospital: ";
numberOfDays = readNotNegative();
cout << "Enter daily rate: ";
dailyRate = readNotNegative();
}
cout << "Enter charges for hospital services: ";
hospitalServices = readNotNegative();
cout << "Enter hospital medication charges: ";
hospitalMedication = readNotNegative();
int totalCharges;
if (patientType == 0) {
totalCharges = computeTotalCharges(numberOfDays, dailyRate, hospitalServices,
hospitalMedication);
} else {
totalCharges = computeTotalCharges(hospitalServices, hospitalMedication);
}
cout << "Total charges: " << totalCharges << endl;
system("pause");
}