Help with calculations

Hi, I've written this code for homework (this is part one) and now I have to do a part two by modifying my code. I'm a little confused as to how/where implement these changes. I kind of have an idea and tried implementing it but it didn't work very well as I just kept getting confused even more. These are the changes I have to make, any tips? Thanks.

Modify the program in Primary Mission 01 so that it computes and displays the charges for a patient’s hospital stay (if one was necessary).

The program should ask if the patient was admitted as an in-patient or an out-patient.

If the patient was an in-patient, the following data should be entered before entering information on the injuries [We have to charge for treating the injuries in addition to charging for the hospital stay]:

The number of days spent in the hospital
The daily rate for the type of room the patient needed
Include this new information on the billing report.

Be sure to validate the new data input by the user.

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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

int main()
{
	//Declarations
	vector<string> injuries(8);
	vector<int> prices(8);

	string name;
	double employeeId;
	int cases = 0;
	int sumOfPrices = 0;
	int injuryCount = 0;
	vector<int> listOfInjuries(20);

	//Injury list
	injuries[0] = "Severe Abrasions and Bruising";
	injuries[1] = "Cuts with Stiches";
	injuries[2] = "1st Degree Fractures";
	injuries[3] = "2nd Degree Fractures";
	injuries[4] = "Burn Treatment (all degrees)";
	injuries[5] = "Severed Appendage (Fingers/Toes)";
	injuries[6] = "Severed Appendages (Arms/Legs)";
	injuries[7] = "Concussion";

	//Prices for each injury
	prices[0] = 20;
	prices[1] = 60;
	prices[2] = 150;
	prices[3] = 350;
	prices[4] = 200;
	prices[5] = 180;
	prices[6] = 430;
	prices[7] = 45;


	//Accepting user input (patients name and employee ID)
		cout << "Please enter the patient's first and last name: ";
		getline(cin, name);
		cout << "Please enter employee ID: ";
		cin >> employeeId;
	
	while (cases != 8)
	{	//Displaying injury types and selection input
		cout << "\nFor " << "'" << injuries[0] << "'" << "\t- Enter '0' " << endl;
		cout << "For " << "'" << injuries[1] << "'" << "\t\t\t- Enter '1' " << endl;
		cout << "For " << "'" << injuries[2] << "'" << "\t\t- Enter '2' " << endl;
		cout << "For " << "'" << injuries[3] << "'" << "\t\t- Enter '3' " << endl;
		cout << "For " << "'" << injuries[4] << "'" << "\t- Enter '4' " << endl;
		cout << "For " << "'" << injuries[5] << "'" << "\t- Enter '5' " << endl;
		cout << "For " << "'" << injuries[6] << "'" << "\t- Enter '6' " << endl;
		cout << "For " << "'" << injuries[7] << "'" << "\t\t\t- Enter '7' " << endl;

		cout << "\nIf no other injuries" << "\t\t\t- Enter '8' " << endl;
		cin >> cases;

		if (cases > 8 || cases < 0)
		{
			cout << "Enter a valid number!" << endl;
			cout << injuries[0] << "\t - Type '0' " << endl;
			cout << injuries[1] << "\t - Type '1' " << endl;
			cout << injuries[2] << "\t - Type '2' " << endl;
			cout << injuries[3] << "\t - Type '3' " << endl;
			cout << injuries[4] << "\t - Type '4' " << endl;
			cout << injuries[5] << "\t - Type '5' " << endl;
			cout << injuries[6] << "\t - Type '6' " << endl;
			cout << injuries[7] << "\t - Type '7' " << endl;
			cout << "No other injuries" << "\t - Type '8' " << endl;
			cin >> cases;
		}
		//Calculating the price
		sumOfPrices = sumOfPrices + prices[cases];

		listOfInjuries[injuryCount] = cases;

		injuryCount++;
	}//End of while loop

	if (injuryCount - 1 > 5)
	{	//Calculating the 10% off
		sumOfPrices = sumOfPrices - sumOfPrices * 0.10;

	}//End of if statement
	//Displaying the patients bill
	cout << endl;
	cout << "Patients name: " << "\t" << name << endl;
	cout << "Employee ID: " << "\t" << employeeId << endl;
	cout << "Total number of injuries: " << injuryCount - 1 << endl;

	//Displaying the injury and cost on the patients bill
	for (int displayCount = 0; displayCount < injuryCount - 1; displayCount++)
	{
		int list = listOfInjuries[displayCount];

		cout << injuries[list] << "\t$" << prices[list] << endl;
		
	}//End of 'for' loop
	
	cout << "Total cost: " << "\t" << "$" << sumOfPrices << endl;

	system("PAUSE");
	return 0;
}
Last edited on
This is how I was trying to implement the rest but not sure.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
do
	{
		cout << "Please enter the patient's first and last name: ";
		getline(cin, name);
		cout << "Please enter employee ID: ";
		cin >> employeeId;
		cout << "Was the person admitted as an in-patient? (y/n): ";
		cin >> userInput;

		validInput = (userInput == 'y') || (userInput == 'n');

	} while (!validInput);

	userChoice = (userInput == 'y');
vector<int> prices(8);
try change it into double , this will fix your cal.
vector<double> prices(8);
Alright thanks. And I guess that what I'm most concerned about is as to where implement the changes being asked to make to the program. Like which line would be the best place to add the new modifications?
and also add a variable that will hold the tax. i mean the 10% off so that the computation for it will be more accurate
Topic archived. No new replies allowed.