Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- double patientCharges(int, double, double, double);//in-patient
- double patientCharges(double, double); //out-patient
- char getPatientType();
- char option;
- int main()
- {
- double dailyRate=0, addCharges=0, addServices=0, total=0; //declaring doubles
- int daysStayed=0;
- char option;
- option = getPatientType();
- if (option == 'I')
- {
- cout << "How many days did the patient stay in the hospital? \n";
- cin >> daysStayed;
- while (daysStayed < 0)
- {
- cout << "Enter an integer greater than 0 \n";
- while (!(cin >> daysStayed)) //error handling
- {
- cin.clear();
- cin.ignore('\n');
- }
- }
- cout << "What is the daily rate for this patient? \n";
- cin >> dailyRate;
- while (dailyRate < 0)
- {
- cout << "Enter an integer greater than 0 \n";
- while (!(cin >> dailyRate))
- {
- cin.clear();
- cin.ignore('\n');
- }
- }
- cout << "Are there any additional medicene for this patient? \n";
- cin >> addCharges;
- while (addCharges < 0)
- {
- cout << "Enter an integer greater than 0 \n";
- while (!(cin >> addCharges))
- {
- cin.clear();
- cin.ignore('\n');
- }
- }
- cout << "Are there any additional services for this patient(such as lab tests, etc?) \n";
- cin >> addServices;
- while (addCharges < 0)
- {
- cout << "Enter an integer greater than 0 \n";
- while (!(cin >> addCharges))
- {
- cin.clear();
- cin.ignore('\n');
- }
- total = patientCharges(daysStayed, addCharges, dailyRate, addServices);
- cout << total;
- }
- total = patientCharges(daysStayed, addCharges, dailyRate, addServices); //using all 4 values to give it to the function with 4 inputs
- cout << total;
- }
- if (option == 'O')
- {
- cout << "Are there any additional medicene for this patient? \n";
- while (!(cin >> addCharges))
- {
- cin.clear();
- cin.ignore('\n');
- }
- cout << "Are there any additional services for this patient(such as lab tests, etc?) \n";
- while (!(cin >> addCharges))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Woah bad data, try again";
- }
- total = patientCharges(addCharges, addServices);
- cout << total;
- }
- return 0;
- }
- double patientCharges(int daysStayed, double dailyRate, double addCharges, double addServices)
- {
- double perday = daysStayed*dailyRate;
- double total = perday + addCharges + addServices;
- return total;
- }
- double patientCharges(double addCharges, double addServices) //both functions for adding the prices
- {
- double total = addCharges + addServices;
- return total;
- }
- char getPatientType() //small menu with error handling that cant handle integers due to strings not like being compared.
- {
- cout << "Was this patient admitted as an In-Patient or and Out-Patient? I for in, O for Out \n ";
- cin >> option;
- while (option != 'I' && option != 'O') //A logical error that works but breaks
- {
- cout << "Please try again\n";
- cin >> option;
- }
- return option;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement