### Simple problem but cant seem to fix

here's my code:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235`` ``````#include "stdafx.h" #include #include 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.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237`` ``````#include "stdafx.h" #include #include 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.