"chp6 Overloaded Hospital" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "chp6 Overloaded Hospital" answered properly. Developers are finding an appropriate answer about chp6 Overloaded Hospital related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like chp6 Overloaded Hospital. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on chp6 Overloaded Hospital. 

chp6 Overloaded Hospital

By Unsightly UnicornUnsightly Unicorn on May 01, 2021
#include <iostream>
using namespace std;

double inputValidate(double);
char userChoice(char);
double calculateTotalCharges(double, double);
double calculateTotalCharges(double, double, double, double);

int main()
{
    char user_choice; // 1 or 2

    double days_spent,
           daily_rate,
           med_charges,
           services_charge,
           total_charges;

    cout << "Where you admitted as an " << endl
         << "in-patient or an out-patient? " << endl
         << "Enter 1 for in-patient or 2 for out-patient"
         << endl;
     
    user_choice = userChoice(user_choice);

    if (user_choice == '1')
    {
        cout << "Number of days spent in the hospital: ";
        days_spent = inputValidate(days_spent);

        cout << "Daily rate: $";
        daily_rate = inputValidate(daily_rate);

        cout << "Hospital medication charges: $";
        med_charges = inputValidate(med_charges);

        cout << "Charges for hospital services\n"
            << "(lab tests, etc.): $";
        services_charge = inputValidate(services_charge);

        total_charges = calculateTotalCharges(days_spent,
                                              daily_rate,
                                              med_charges,
                                              services_charge);
                        
        cout << "total_charges = $" 
            << total_charges
            << endl;
    }
    else
    {
        cout << "Hospital medication charges: $";
        med_charges = inputValidate(med_charges);

        cout << "Charges for hospital services\n"
            << "(lab tests, etc.): $";
        services_charge = inputValidate(services_charge);

        total_charges = calculateTotalCharges(med_charges,
                                              services_charge);

        cout << "total_charges = $" 
               << total_charges
               << endl;
    }
    

    return 0;
}

char userChoice(char letter)
{
    cin >> letter;
    // Error check algorithim
    while (!((letter == '1') || (letter == '2')))
    {
        // Explain error
        cout << "ERROR: enter 1 or 2: ";
        // Clear input stream
        cin.clear();
        // Discard previous input
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
        // Receive input again
        cin >> letter;
    }
    return letter;
}

double inputValidate(double num)
{
    
    while(!(cin >> num) || num < 0)
    {
        cout << "Error. Number must not be "
             << " 0 or greater:";
        cin.clear();
        cin.ignore(numeric_limits<streamsize>::max(), '\n');
    }

    return num;
}

double calculateTotalCharges(double med_charges, 
                             double services_charge)
{
     return med_charges + services_charge;
}

double calculateTotalCharges(double days_spent, 
                             double daily_rate, 
                             double med_charges, 
                             double services_charge)
{
     return (days_spent * daily_rate) + med_charges + services_charge;
}

Source: jesushilarioh.com

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on chp6 Overloaded Hospital can get a collection of related answers to their query. Programmers need to enter their query on chp6 Overloaded Hospital related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about chp6 Overloaded Hospital for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of chp6 Overloaded Hospital while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "chp6 Overloaded Hospital". Visit this developer's friendly online web community, CodeProZone, and get your queries like chp6 Overloaded Hospital resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "chp6 Overloaded Hospital"

View All Whatever queries

Whatever queries related to "chp6 Overloaded Hospital"

Browse Other Code Languages

CodeProZone