Programming Challenge

i need to complete to code

output should read
This program will compute patient hospital charges.
Enter I for in-patient or O for out-patient: O

Lab fees and other service charges: $300
Medication charges: $500

**************************
Hospital Billing Statement
**************************
Lab & Services $ 300.00
Medication $ 500.00
Total charges $ 800.00
**************************

Press any key to continue . . .
This program will compute patient hospital charges.
Enter I for in-patient or O for out-patient: i

Number of days in the hospital: 5
Daily room rate: $800
Lab fees and other service charges: $350
Medication charges: $250

**************************
Hospital Billing Statement
**************************
Room charges $ 4000.00
Lab & Services $ 350.00
Medication $ 250.00
Total charges $ 4600.00
**************************

Press any key to continue . . .




//Create the functions validateData, patientCharges
//Using the prototypes as reference
//You do not need to modify main
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function prototypes
double validateData(double, string);
double patientCharges(int, double, double, double); // In-patient
double patientCharges(double, double); // Out-patient

int main()
{
char patientType; // I=in-patient, O=out-patient
int days; // Number of days of hospital stay
double roomRate, // Daily room rate
medication, // Total medication charges
services, // Total for tests and other services
totalCharges; // Total of all charges

// Input and validate patient type

cout << "This program will compute patient hospital charges.\n";
cout << "Enter I for in-patient or O for out-patient: ";
cin >> patientType;
if (patientType == 'i') // Make i or o uppercase
patientType = 'I';
else if (patientType == 'o')
patientType = 'O';

while (patientType != 'I' && patientType != 'O')
{
cout << "Please enter I or O: ";
cin >> patientType;
if (patientType == 'i') // Make i or o uppercase
patientType = 'I';
else if (patientType == 'o')
patientType = 'O';
}
cout << endl;

// Input and validate data relevant to in-patients


if (patientType == 'I')
{
cout << "Number of days in the hospital: ";
cin >> days;
days = static_cast<int>(validateData(days, "days in hospital"));

cout << "Daily room rate: $";
cin >> roomRate;
roomRate = validateData(roomRate, "daily room rate");
}


cout << "Lab fees and other service charges: $";
cin >> services;
services = validateData(services, "lab fees and other service charges");

cout << "Medication charges: $";
cin >> medication;
medication = validateData(medication, "medication charges");

// Call correct patientCharges function to return total charges
if (patientType == 'I')
totalCharges = patientCharges(days, roomRate, medication, services);
else
totalCharges = patientCharges(medication, services);

// Display the billing statment
double patientCharges(double, double)

cout << fixed << showpoint << setprecision(2) << endl;
cout << "************************** \n";
cout << "Hospital Billing Statement \n";
cout << "************************** \n";
if (patientType == 'I')
cout << "Room charges $" << setw(8) << days * roomRate << endl;
if (services > 0.0)
cout << "Lab & Services $" << setw(8) << services << endl;
if (medication > 0.0)
cout << "Medication $" << setw(8) << medication << endl;
cout << "Total charges $" << setw(8) << totalCharges << endl;
cout << "**************************\n";

cout << endl;
system("pause");
return 0;
}

1.
Please learn to use code tags, they make reading and commenting on source code MUCH easier.

How to use code tags: http://www.cplusplus.com/articles/jEywvCM9/

There are other tags available.

How to use tags: http://www.cplusplus.com/articles/z13hAqkS/

HINT: you can edit your post and add code tags.

Some formatting & indentation would not hurt either


2.
M'ok, you've given us your assignment, you've written some code. Now what? What are we supposed to do?

Problems you are having with your code, we can help. You have to tell us what the problems are, if any. In detail.

We aren't mind-readers.
With tags and formatted for better readability:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//Create the functions validateData, patientCharges
//Using the prototypes as reference
//You do not need to modify main
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// Function prototypes
double validateData(double, string);
double patientCharges(int, double, double, double); // In-patient
double patientCharges(double, double); // Out-patient

int main()
{
   char patientType; // I=in-patient, O=out-patient
   int days; // Number of days of hospital stay
   double roomRate, // Daily room rate
      medication, // Total medication charges
      services, // Total for tests and other services
      totalCharges; // Total of all charges

      // Input and validate patient type

   cout << "This program will compute patient hospital charges.\n";
   cout << "Enter I for in-patient or O for out-patient: ";
   cin >> patientType;
   if (patientType == 'i') // Make i or o uppercase
      patientType = 'I';
   else if (patientType == 'o')
      patientType = 'O';

   while (patientType != 'I' && patientType != 'O')
   {
      cout << "Please enter I or O: ";
      cin >> patientType;
      if (patientType == 'i') // Make i or o uppercase
         patientType = 'I';
      else if (patientType == 'o')
         patientType = 'O';
   }
   cout << endl;

   // Input and validate data relevant to in-patients


   if (patientType == 'I')
   {
      cout << "Number of days in the hospital: ";
      cin >> days;
      days = static_cast<int>(validateData(days, "days in hospital"));

      cout << "Daily room rate: $";
      cin >> roomRate;
      roomRate = validateData(roomRate, "daily room rate");
   }


   cout << "Lab fees and other service charges: $";
   cin >> services;
   services = validateData(services, "lab fees and other service charges");

   cout << "Medication charges: $";
   cin >> medication;
   medication = validateData(medication, "medication charges");

   // Call correct patientCharges function to return total charges
   if (patientType == 'I')
      totalCharges = patientCharges(days, roomRate, medication, services);
   else
      totalCharges = patientCharges(medication, services);

   // Display the billing statment
   double patientCharges(double, double)

      cout << fixed << showpoint << setprecision(2) << endl;
   cout << "************************** \n";
   cout << "Hospital Billing Statement \n";
   cout << "************************** \n";
   if (patientType == 'I')
      cout << "Room charges $" << setw(8) << days * roomRate << endl;
   if (services > 0.0)
      cout << "Lab & Services $" << setw(8) << services << endl;
   if (medication > 0.0)
      cout << "Medication $" << setw(8) << medication << endl;
   cout << "Total charges $" << setw(8) << totalCharges << endl;
   cout << "**************************\n";

   cout << endl;
   system("pause");
   return 0;
}

Trying to define a function inside main (line 74) is NOT allowed. There are functions that can be defined within a block of code, lambdas, but your functions are not lambdas.

Plus you are missing the other two function definitions you declared on lines 10-11.

Using code tags and proper formatting makes potential problems with code stand out and easier to say where the problems are.
Last edited on
As a first refactor, consider which needs ValidateData() function to be completed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <iomanip>
#include <string>

double validateData(double, const std::string&);
double patientCharges(int, double, double, double);
double patientCharges(double, double);

int main() {
	char patientType {};
	int days {};
	double roomRate {},
		medication {},
		services {},
		totalCharges {};

	std::cout << "This program will compute patient hospital charges.\n";

	std::cout << "Enter I for in-patient or O for out-patient: ";
	std::cin >> patientType;

	if (patientType == 'i')
		patientType = 'I';
	else if (patientType == 'o')
		patientType = 'O';

	while (patientType != 'I' && patientType != 'O') {
		std::cout << "Please enter I or O: ";
		std::cin >> patientType;

		if (patientType == 'i')
			patientType = 'I';
		else if (patientType == 'o')
			patientType = 'O';
	}

	std::cout << '\n';

	if (patientType == 'I') {
		std::cout << "Number of days in the hospital: ";
		std::cin >> days;
		days = static_cast<int>(validateData(days, "days in hospital"));

		std::cout << "Daily room rate: $";
		std::cin >> roomRate;
		roomRate = validateData(roomRate, "daily room rate");
	}

	std::cout << "Lab fees and other service charges: $";
	std::cin >> services;
	services = validateData(services, "lab fees and other service charges");

	std::cout << "Medication charges: $";
	std::cin >> medication;

	medication = validateData(medication, "medication charges");

	if (patientType == 'I')
		totalCharges = patientCharges(days, roomRate, medication, services);
	else
		totalCharges = patientCharges(medication, services);

	std::cout << std::fixed << std::showpoint << std::setprecision(2) << '\n';
	std::cout << "************************** \n";
	std::cout << "Hospital Billing Statement \n";
	std::cout << "************************** \n";

	if (patientType == 'I')
		std::cout << std::setw(15) << std::left << "Room charges " << "$" << std::right <<  std::setw(8) << days * roomRate << '\n';

	if (services > 0.0)
		std::cout << std::setw(15) << std::left << "Lab & Services " << "$" << std::right << std::setw(8) << services << '\n';

	if (medication > 0.0)
		std::cout << std::setw(15) << std::left << "Medication " << "$" << std::right << std::setw(8) << medication << '\n';

	std::cout << std::setw(15) << std::left << "Total charges " << "$" << std::right << std::setw(8) << totalCharges << '\n';
	std::cout << "**************************\n\n";
}

// This needs to be completed
double validateData(double data, const std::string& str) {
	return data;
}

double patientCharges(int d, double r, double m, double s) {
	return r * d + m + s;
}

double patientCharges(double med, double serv) {
	return med + serv;
}



This program will compute patient hospital charges.
Enter I for in-patient or O for out-patient: i

Number of days in the hospital: 4
Daily room rate: $400
Lab fees and other service charges: $56
Medication charges: $87

**************************
Hospital Billing Statement
**************************
Room charges   $ 1600.00
Lab & Services $   56.00
Medication     $   87.00
Total charges  $ 1743.00
**************************

Thank you
Registered users can post here. Sign in or register to post.