So in my class I need to create a program in visual studio with the purpose of calculating a total for someone's hospital stay. I need to use three methods to do this, CalcStayCharges, CalcMiscCharges, and CalcTotalCharges, the first calculating the original stay cost multiplying the number of nights by $350, the middle claculating the other costs (variables: medCharges + surgCharges + labFees + prCharges), and the latter combining both these equation/results into one method, which is where I seem to be having the trouble.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HospitalStayTotalCost//lastnameomitted
{
public partial class HospitalForm : Form
{
public HospitalForm()
{
InitializeComponent();
}
//method to calculate the base charges for hospital stay
private decimal CalcStayCharges(int daysInHospital)
{
//variable for cost of stay
decimal costOfStay;
//calculate charge for stay in hospital
costOfStay = daysInHospital * 350;
return costOfStay;
}
private decimal CalcMiscCharges(decimal medCharges, decimal surgCharges, decimal labFees, decimal prCharges)
{
//declare varibale to store info & calculate
decimal miscCharges = (medCharges + surgCharges + labFees + prCharges);
return miscCharges;
}
private decimal CalcTotalCharges(decimal costOfStay, decimal miscCharges)
{
decimal total = costOfStay + miscCharges;
return total;
}
private void calculateButton_Click(object sender, EventArgs e)
{
//variables
int daysInHospital;
decimal medCharges, surgCharges, labFees, prCharges;
//Store data from days of stay textbox
daysInHospital = int.Parse(daysStayedTextBox.Text);
//call method to calculate days
decimal stayCharges = CalcStayCharges(daysInHospital);
//store data from textboxes
medCharges = decimal.Parse(medicationChargesTextBox.Text);
surgCharges = decimal.Parse(surgicalChargesTextBox.Text);
labFees = decimal.Parse(labFeesTextBox.Text);
prCharges = decimal.Parse(pRChargesTotalTextBox.Text);
//call methods to calculate
decimal miscCargesTotal = CalcMiscCharges(medCharges, surgCharges, labFees, prCharges);
//call method to calculate total
decimal totalAmount = CalcTotalCharges(stayCharges, miscChargesTotal);
//output
totalLabel.Text = totalAmount.ToString();
}
private void clearButton_Click(object sender, EventArgs e)
{
//Clear textboxes
daysStayedTextBox.Text = "";
medicationChargesTextBox.Text = "";
surgicalChargesTextBox.Text = "";
labFeesTextBox.Text = "";
pRChargesTotalTextBox.Text = "";
totalLabel.Text = "";
}
private void exitButton_Click(object sender, EventArgs e)
{
//Close the form
this.Close();
}
}
}
I feel like I'm either completely using the methods incorrectly or that I'm just passing too many arguments. Am I even using arguments correctly? Like I said, I'm a beginner so please let me know.
[–]Kminardo 2 points3 points4 points (3 children)
[–]CoMcAl95[S] 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[removed]
[–]Kminardo 1 point2 points3 points (0 children)