6
Answers

Hospital Charges c#

Tiago Leao

Tiago Leao

9y
5.8k
1
Create an application that calculates the total cost of a hospital stay. The application should accept the following input:

- The number of days spent in the hospital
- The amount of medication charges
- The amount of surgical charges
- The amount of lab fees
- The amount of physical rehabilitation charges

The hospital charges $350 per day.

Create the following methods:

CalcStayCharges Calculates and returns the base charges for the hospital stay. The is compound as $350 times the number of days in the hospital.

CalcMiscCharges Calculates and returns the total of the medication, surgical, lab, and physical rehabilitation charges.

CalcTotalCharges Calculates and returns the total charges.

Input Validation: Do not accept invalid value for length of stay, medication charges, surgical charges, lab fees, or  rehab charges.

There will be 5 text boxes: Length of Stay (Days), Medication, Surgical Charges, Lab Fees and rehab. A label should contain the Total Cost. There will be two buttons: Calculate Charges and Close

**I need help writing the correct code so this problem executes properly. Thanks!**

This is what I have so far. I am lost. Please help


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Hospital_Charges
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // These methods accept the number of days at the hospital
        // and medical charges as arguments and return the
        // equivalent total of charges.
        private double CalcStayCharges(double days)
        {
            return days * 350.0;
        }

        private double CalcMiscCharges(double medical, double surgical, double lab, double rehab)
        {
            return (medical+ surgical + lab + rehab);
        }

        private void calculateButton_Click(object sender, EventArgs e)
        {
            // Variables to hold the number of days spent at the hospital, amount of medication, surgical, lab and rehab charges.
            double days, staytotal, medical, surgical, lab, rehab, totalCharges;

             // Get the number of days.
            if (double.TryParse(daysTextBox.Text, out days))
            {
                // Calculate the stay charge.
                staytotal = CalcStayCharges(days);

                // Display the stay charge.
                totalStayLabel.Text = staytotal.ToString("n1");

                // Calculate the other services.
                totalCharges = CalcMiscCharges(medical, surgical, lab, rehab);       
            }
            else
            {
                // Display an error message.
                MessageBox.Show("Enter a valid number.");
            }            
        }

        private void exitButton_Click(object sender, EventArgs e)
        {
            // Close the form.
            this.Close();
        }

    }
}

Answers (6)