Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hospital Charges ASSIGNMENT: Write a program to calculate and display the amount

ID: 3701677 • Letter: H

Question

Hospital Charges

ASSIGNMENT:

Write a program to calculate and display the amount of the charges for a hospital stay. Create a global constant for the daily fee of a hospital room ($350.00/day). Ask the user for:

The number of days spent in the hospital

The amount of the medication charges

The amount of the surgical charges

The amount of the lab fees

The amount of the physical rehabilitation charges

Then, using functions, calculate the stay charges (number of days * daily fee for the room), the miscellaneous charges (the total of the medication, surgical, lab, and physical rehabilitation charges), and the total charges. Finally, using a 4th function, display the charges.

There is no validation in this program.

Example Run #1: (bold type is what is entered by the user)

Enter the number of days spent in the hospital: 3

Enter the amount of the medication charges: $125.00

Enter the amount of the surgical charges: $500.00

Enter the amount of the lab fees: $400.00

Enter the amount of the physical rehabilitation charges: $0.00

The cost of the hospital stay is $xxxx.xx

The cost of the miscellaneous charges is $xxxx.xx.

The total cost of the hospital stay is $xxxx.xx.

The example run shows EXACTLY how your program input and output will look.

Write in C, with printf and scanf statements. Create a global constant and use functions.

Explanation / Answer

PROGRAM

#include<stdio.h>

float roomRent=3500.00; // Global constant variable "roomRent"

// Declare and implement calCharge() function with one argument "numDays"

float calCharge(int numDays)

{

float stayCharge=roomRent*numDays; // calculate total charge of room rent

return stayCharge; // return total room rent value

}

// Declare and implement misCharge() function with four arguments "medCharge,surCharge,labFee,phyReh"

float misCharge(float medCharge,float surCharge,float labFee,float phyReh)

{

float msc=medCharge+surCharge+labFee+phyReh; // calculate total miscellaneous charge

return msc; // return total miscellaneous charge

}

//Declare and implement totCharge() function with five arguments "numDays,medCharge,surCharge,labFee,phyReh"

float totCharge(int numDays,float medCharge,float surCharge,float labFee,float phyReh)

{

return calCharge(numDays)+misCharge(medCharge,surCharge,labFee,phyReh); // calculate and return total charge

}

// Declare and implement dispCharge() function for displaying charges

void dispCharge(int numDays,float medCharge,float surCharge,float labFee,float phyReh)

{

printf(" The cost of the hospital stay is $%.2f",calCharge(numDays)); // display hospital stay charge using calling calCharge() function

printf(" The cost of the miscellaneous charges is $%.2f",misCharge(medCharge,surCharge,labFee,phyReh)); // display miscellaneous charge using calling misCharge() function

printf(" The total cost of the hospital stay is $%.2f",totCharge(numDays,medCharge,surCharge,labFee,phyReh)); // display total medical charge using calling totCharge() function

}

int main()

{

int nDays; // Declare integer variable nDays

float mChg,sChg,labChg,phyChg; // Declare float variables mChg,sChg,labChg,phyChg

printf(" Enter the number of days spent in the hospital: ");

scanf("%d",&nDays); // read integer number of days

printf(" Enter the amount of the medication charges: $");

scanf("%f",&mChg); // read float medical Charge

printf(" Enter the amount of the surgical charges: $");

scanf("%f",&sChg); // read float surcharge

printf(" Enter the amount of the lab fees: $");

scanf("%f",&labChg); // read float lab charge

printf(" Enter the amount of the physical rehabilitation charges: $");

scanf("%f",&phyChg); // read float physical rehabilitation charge

dispCharge(nDays,mChg,sChg,labChg,phyChg); // calling dispCharge() function

return 0;

}

OUTPUT


Enter the number of days spent in the hospital: 3

Enter the amount of the medication charges: $125.00

Enter the amount of the surgical charges: $500.00

Enter the amount of the lab fees: $400.00

Enter the amount of the physical rehabilitation charges: $0.00

The cost of the hospital stay is $10500.00
The cost of the miscellaneous charges is $1025.00
The total cost of the hospital stay is $11525.00