This program is already posted in book section: Starting out withC++, Tony Gaddi
ID: 3617753 • Letter: T
Question
This program is already posted in book section: Starting out withC++, Tony Gaddis (chapter 6 question 14PC)You could respond as a new solution or try to fix and run thisprogram please also put the input validation for program as (Do notaccept negative number for any data) well.
#include<iostream>
#include<cmath>
using namespace std;
int out(int, int, int, int);
int in(int, int);
void main()
{
char ans;
int days, d_rate, service_charges, med_charges,total_charges;
cout<<"patient admitted as an in-patientor an out-patient?";
cout<<" Enter 'i' for in-patient and 'o'for out-patient: ";
cin>>ans;
if (ans=='o' || ans=='o')
{
cout<<"THe number ofdays spent in the hospital: ";
cin>>days;
while (days<0)
{
cout<<"ERROR: Reenter: ";
cin>>days;
}
cout<<"The daily rate:";
cin>>d_rate;
while (d_rate<0)
{
cout<<"ERROR: Reenter: ";
cin>>days;
}
cout<<"Charges forservices (lab tests, etc.):";
cin>>service_charges;
while(service_charges<0)
{
cout<<"ERROR: Reenter: ";
cin>>service_charges;
}
cout<<"Hospitalmedication charges: ";
cin>>med_charges;
while (med_charges<0)
{
cout<<"ERROR: Reenter: ";
cin>>med_charges;
total_charges=out (days,d_rate, service_charges, med_charges);
cout<<"The totalcharges of patient's hopital stay is "<<total_charges;
}
if (ans=='i' || ans=='I')
{
cout<<"Charges for services (lab tests,etc.): ";
cin>>service_charges;
while (service_charges<0)
{
cout<<"ERROR: Reenter:";
cin>>service_charges;
}
cout<<"Hospital medication charges: ";
cin>>med_charges;
while (med_charges<0)
{
cout<<"ERROR: Reenter:";
cin>>med_charges;
}
total_charges=in(service_charges,med_charges);
cout<<"The total charges of patient'shospital stay is "<<total_charges<<endl;
}
system ("pause");
}
int out(int a, int b, int c, int d)
{
returna*b+c+d;
}
int in(int x, int y)
{
returnx+y;
}
Explanation / Answer
x.Xr,
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.