Simple problem but cant seem to fix

here's my code:

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

class PatientAccount
{
	private:
		int days;
		float dailyRate;
		string name;
		double charges1;

	public:
		PatientAccount(int, float, string);
		double getCharges(double& charges1);
		int getDays();
		float getDailyRate();
		string getPatientName();
		void displayPatientInformation();
};

PatientAccount::PatientAccount(int dys = 0, float dr = 0, string n = " ")
{
	days = dys;
	dailyRate = dr;
	name = n;
}

int PatientAccount::getDays()
{
	std::cout << "Enter the number of days spent in hospital: ";
	std::cin >> days;

	return days;
}

float PatientAccount::getDailyRate()
{
	std::cout << "Enter the daily rate amount for each day spent in hospital: $";
	std::cin >> dailyRate;

	return dailyRate;
}

std::string PatientAccount::getPatientName()
{
	std::cout << "Enter the patients name: ";
	getline(std::cin, name);

	return name;
}

double PatientAccount::getCharges(double& charges1)
{
	charges1 = 0;

	return charges1;
}

class Surgery
{
	private:
		double charges2;

	public:
		Surgery(double);
		double getSurCharges(double& charges2);
		void displaySurgeryInformation();
};

Surgery::Surgery(double c = 0)
{
	charges2 = c;
}

double Surgery::getSurCharges(double& charges2)
{
	charges2 = 0;

	return charges2;
}

class Pharmacy
{
	private:
		double charges3;

	public:
		Pharmacy(double);
		double getPharmCharges(double& charges3);
		void displayPharmacyInformation();
};

Pharmacy::Pharmacy(double c = 0)
{
	charges3 = c;
}
double Pharmacy::getPharmCharges(double& charges3)
{
	charges3 = 0;

	return charges3;
};

void PatientAccount::displayPatientInformation()
{
	PatientAccount patient(getDays(), getDailyRate(), getPatientName());

	charges1 = days * dailyRate;

	std::cout << "Patient Account Information" << endl;
	std::cout << "-------------------------------------------" << endl;
	std::cout << "Patients Name:                   " << name << endl;
	std::cout << "Total Hospital Days:             " << days << endl;
	std::cout << "Hospital Daily Rate;            $" << dailyRate << endl;
	std::cout << "Total Charges:                  $" << charges1 << endl;
	std::cout << "-------------------------------------------" << endl;
}

void Surgery::displaySurgeryInformation()
{
	double Brain = 15000,
		   Respiratory = 3000,
		   Hand = 6000,
		   Leg = 4560,
		   Kidney = 7500,
		   Arm = 2435;

	int selection = 0;
	std::cout << "\n";
	std::cout << "Enter the number for the surgery performed." << endl;

	do
	{
		std::cout << "(1) Brain" << endl;
		std::cout << "(2) Respiratory" << endl;
		std::cout << "(3) Hand" << endl;
		std::cout << "(4) Leg" << endl;
		std::cout << "(5) Kidney" << endl;
		std::cout << "(6) Arm" << endl;
		std::cout << "(0) Update Surgery Information" << endl;
		std::cout << "\nEnter Selection: ";
		std::cin >> selection;

		switch (selection)
		{
			case 1: charges2 += Brain; break;
			case 2: charges2 += Respiratory; break;
			case 3: charges2 += Hand; break;
			case 4: charges2 += Leg; break;
			case 5: charges2 += Kidney; break;
			case 6: charges2 += Arm; break;
			case 0: break;
		}
	} while (selection != 0);

	std::cout << "\nSurgery Information" << endl;
	std::cout << "-------------------------------------------" << endl;
	std::cout << "Total Charges:                  $" << charges2 << endl;
	std::cout << "-------------------------------------------" << endl;
}

void Pharmacy::displayPharmacyInformation()
{
	Pharmacy patient(getPharmCharges(charges3));

	 double Vicodin = 60,
		   Amoxicillin = 25,
		   Cephalexin = 15,
		   Baclofen = 45,
		   Valium = 20,
		   Ibuprofen = 10;

        int selection = 0;
		std::cout << "\n";
		std::cout << "Enter number for medication prescribed." << endl;
        
		do
		{
			std::cout << "(1) Vicodin" << endl;
		    std::cout << "(2) Amoxicillin" << endl;
			std::cout << "(3) Cephalexin" << endl;
			std::cout << "(4) Baclofen" << endl;
			std::cout << "(5) Valium" << endl;
			std::cout << "(6) Ibuprofen" << endl;
			std::cout << "(0) Update Medication Costs" << endl;
			std::cout << "\nEnter Selection: ";
			std::cin >> selection;
		  
			switch (selection)
			{
				case 1: charges3 += Vicodin; break;
				case 2: charges3 += Amoxicillin; break;
				case 3: charges3 += Cephalexin; break;
				case 4: charges3 += Baclofen; break;
				case 5: charges3 += Valium; break;
				case 6: charges3 += Ibuprofen; break;
				case 0: break;
			}
	 	} while (selection != 0);

		std::cout << "\nPatient Pharmacy information" << endl;
		std::cout << "----------------------------------------------------" << endl;
		std::cout << "Total Charges:                  $" << charges3 << endl;
		std::cout << "----------------------------------------------------" << endl;
}

int main(double charges1, double charges2, double charges3)
{
	PatientAccount patient1;
	Surgery patient2;
	Pharmacy patient3;

	cout.setf(ios_base::fixed, ios_base::floatfield);
	cout.precision(2);

	patient1.displayPatientInformation();
	patient2.displaySurgeryInformation();
	patient3.displayPharmacyInformation();
	
	double totalCharges;
	
	totalCharges = (charges1 + charges2) + charges3;

	cout << "\n";
	cout << "The Patients Total Bill is $" << totalCharges << endl;

	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}


The totalcost in the main function is not adding charges1, charges2, and charges3. Its outputting a random very very huge number, anyone know what i did wrong the code or calculation to fix this problem.
This shouldn't even compile... Unless I'm missing something?

There is no declaration of main that takes double, double, double (line 209)
Last edited on
It compiles without any warnings or errors, im passing the charges1, charges2, and charges3 to the main function from the classes, when i run it, all the charges variables get updated and display the correct amount its just that totalcharges variables that not displaying right, if anyone you can see why, or give me a better solution to pass those variables, i would appreciate it.
I found the problem, i also had to make the void function take and pas the charges to main. heres the code that works correctly now.

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

class PatientAccount
{
	private:
		int days;
		float dailyRate;
		string name;
		double charges1;

	public:
		PatientAccount(int, float, string);
		double getCharges(double& charges1);
		int getDays();
		float getDailyRate();
		string getPatientName();
		void displayPatientInformation(double& charges1);
};

PatientAccount::PatientAccount(int dys = 0, float dr = 0, string n = " ")
{
	days = dys;
	dailyRate = dr;
	name = n;
}

int PatientAccount::getDays()
{
	std::cout << "Enter the number of days spent in hospital: ";
	std::cin >> days;

	return days;
}

float PatientAccount::getDailyRate()
{
	std::cout << "Enter the daily rate amount for each day spent in hospital: $";
	std::cin >> dailyRate;

	return dailyRate;
}

std::string PatientAccount::getPatientName()
{
	std::cout << "Enter the patients name: ";
	getline(std::cin, name);

	return name;
}

double PatientAccount::getCharges(double& charges1)
{
	charges1 = 0;

	return charges1;
}

class Surgery
{
	private:
		double charges2;

	public:
		Surgery(double);
		double getSurCharges(double& charges2);
		void displaySurgeryInformation(double& charges2);
};

Surgery::Surgery(double c = 0)
{
	charges2 = c;
}

double Surgery::getSurCharges(double& charges2)
{
	charges2 = 0;

	return charges2;
}

class Pharmacy
{
	private:
		double charges3;

	public:
		Pharmacy(double);
		double getPharmCharges(double& charges3);
		void displayPharmacyInformation(double& charges3);
};

Pharmacy::Pharmacy(double c = 0)
{
	charges3 = c;
}
double Pharmacy::getPharmCharges(double& charges3)
{
	charges3 = 0;

	return charges3;
};

void PatientAccount::displayPatientInformation(double& charges1)
{
	PatientAccount patient(getDays(), getDailyRate(), getPatientName());

	charges1 = days * dailyRate;

	std::cout << "Patient Account Information" << endl;
	std::cout << "-------------------------------------------" << endl;
	std::cout << "Patients Name:                   " << name << endl;
	std::cout << "Total Hospital Days:             " << days << endl;
	std::cout << "Hospital Daily Rate;            $" << dailyRate << endl;
	std::cout << "Total Charges:                  $" << charges1 << endl;
	std::cout << "-------------------------------------------" << endl;
}

void Surgery::displaySurgeryInformation(double& charges2)
{
	Surgery patient(getSurCharges(charges2));

	double Brain = 15000,
		   Respiratory = 3000,
		   Hand = 6000,
		   Leg = 4560,
		   Kidney = 7500,
		   Arm = 2435;

	int selection = 0;
	std::cout << "\n";
	std::cout << "Enter the number for the surgery performed." << endl;

	do
	{
		std::cout << "(1) Brain" << endl;
		std::cout << "(2) Respiratory" << endl;
		std::cout << "(3) Hand" << endl;
		std::cout << "(4) Leg" << endl;
		std::cout << "(5) Kidney" << endl;
		std::cout << "(6) Arm" << endl;
		std::cout << "(0) Update Surgery Information" << endl;
		std::cout << "\nEnter Selection: ";
		std::cin >> selection;

		switch (selection)
		{
			case 1: charges2 += Brain; break;
			case 2: charges2 += Respiratory; break;
			case 3: charges2 += Hand; break;
			case 4: charges2 += Leg; break;
			case 5: charges2 += Kidney; break;
			case 6: charges2 += Arm; break;
			case 0: break;
		}
	} while (selection != 0);

	std::cout << "\nSurgery Information" << endl;
	std::cout << "-------------------------------------------" << endl;
	std::cout << "Total Charges:                  $" << charges2 << endl;
	std::cout << "-------------------------------------------" << endl;
}

void Pharmacy::displayPharmacyInformation(double& charges3)
{
	Pharmacy patient(getPharmCharges(charges3));

	 double Vicodin = 60,
		    Amoxicillin = 25,
		    Cephalexin = 15,
		    Baclofen = 45,
		    Valium = 20,
		    Ibuprofen = 10;

        int selection = 0;
		std::cout << "\n";
		std::cout << "Enter number for medication prescribed." << endl;
        
		do
		{
			std::cout << "(1) Vicodin" << endl;
		    std::cout << "(2) Amoxicillin" << endl;
			std::cout << "(3) Cephalexin" << endl;
			std::cout << "(4) Baclofen" << endl;
			std::cout << "(5) Valium" << endl;
			std::cout << "(6) Ibuprofen" << endl;
			std::cout << "(0) Update Medication Costs" << endl;
			std::cout << "\nEnter Selection: ";
			std::cin >> selection;
		  
			switch (selection)
			{
				case 1: charges3 += Vicodin; break;
				case 2: charges3 += Amoxicillin; break;
				case 3: charges3 += Cephalexin; break;
				case 4: charges3 += Baclofen; break;
				case 5: charges3 += Valium; break;
				case 6: charges3 += Ibuprofen; break;
				case 0: break;
			}
	 	} while (selection != 0);

		std::cout << "\nPatient Pharmacy information" << endl;
		std::cout << "----------------------------------------------------" << endl;
		std::cout << "Total Charges:                  $" << charges3 << endl;
		std::cout << "----------------------------------------------------" << endl;
}

int main(double charges1, double charges2, double charges3)
{
	PatientAccount patient1;
	Surgery patient2;
	Pharmacy patient3;

	cout.setf(ios_base::fixed, ios_base::floatfield);
	cout.precision(2);

	patient1.displayPatientInformation(charges1);
	patient2.displaySurgeryInformation(charges2);
	patient3.displayPharmacyInformation(charges3);
	
	double totalCharges;
	
	totalCharges = (charges1 + charges2) + charges3;

	cout << "\n";
	cout << "The Patients Total Bill is $" << totalCharges << endl;

	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}
Topic archived. No new replies allowed.