| | |
Having problems with my code
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 57
Reputation:
Solved Threads: 0
I have to write a program that must compute and display the charges for a patients hospital stay. first the program should ask if the patient was admitted as an in patient or an out patient. If the patient was as an in-patient the following data should be entered:
the number of days spent in the hospital
the daily rate
charges for hospital services (lab tests, etc.)
hospital medication charges
If the patient was an out patient the following data should be entered:
charges for hospital services (lab tests, etc.)
hosppital medication charges
the program should use two overloaded functions to calculate the total charges. one of the functions should accept arguments for the in patient data, while the other function accepts arguments for out patient data. Both functions should return the total charges.
Input validation: do not accept negative numbers for any information. Im having trouble getting my data to come out right.
And this is what I have to far:
can anyone help?
the number of days spent in the hospital
the daily rate
charges for hospital services (lab tests, etc.)
hospital medication charges
If the patient was an out patient the following data should be entered:
charges for hospital services (lab tests, etc.)
hosppital medication charges
the program should use two overloaded functions to calculate the total charges. one of the functions should accept arguments for the in patient data, while the other function accepts arguments for out patient data. Both functions should return the total charges.
Input validation: do not accept negative numbers for any information. Im having trouble getting my data to come out right.
And this is what I have to far:
// This program computes and displays patient hospital charges.// It uses overloaded functions.#include <iostream>#include <iomanip>using namespace std;// Function prototypesdouble patientCharges(int, double, double, double); // In-patientdouble patientCharges(double, double); // Out-patientint 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; //add code here // Input and validate data relevant to in-patients //add code here // Input and validate data relevant to all patients //add code here // Call correct patientCharges function to return total charges //add code here // Display the billing statment cout << fixed << showpoint << setprecision(2) << endl << endl; 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"; return 0;}// End of main function/************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for in-patients * *************************************************************/double patientCharges(int days, double rate, double med, double serv){ //add code here}// end overload function patientCharges/************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for out-patients * *************************************************************/double patientCharges(double med, double serv){ //add code here}// end overload function patientChargescan anyone help?
•
•
Join Date: Oct 2008
Posts: 57
Reputation:
Solved Threads: 0
// This program computes and displays patient hospital charges.
// It uses overloaded functions.
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes double patientCharges(int, double, double, double);
// In-patientdouble patientCharges(double, double);
// Out-patientint 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;
//add code here
// Input and validate data relevant to in-patients
//add code here
// Input and validate data relevant to all patients
//add code here
// Call correct patientCharges function to return total charges
//add code here
// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
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";
return 0;
}// End of main function/************************************************************* *
patientCharge
* * This function is called by main to calculate and return * * total patient charges for in-patients•
•
Join Date: Oct 2008
Posts: 57
Reputation:
Solved Threads: 0
[ICODE=c++]
#include <iostream
#include <iomanip>
using namespace std;
//function prototypes
double patientcharges(int, double, double, double);
//in- patient double
patientCharges(double,double);
//out-patient
int main()
{
char patientTye;
//I = in-patient;
//O = out-patient;
int days; //num days of hospital stay
double roomRate;
//Daily room rate
double medication;
// Total medication charges
double 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
cout << "Enter I for in-patient or O for out-patient: ";
cin >> patientType;
//add code here
// Input and validate data relevant to in-patients
//add code here
// Input and validate data relevant to all patients
//add code here
// Call correct patientCharges function to return total charge
//add code here
// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
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";
return 0;
}
//Calculate function that i have no clue how to do
[/ICODE]
#include <iostream
#include <iomanip>
using namespace std;
//function prototypes
double patientcharges(int, double, double, double);
//in- patient double
patientCharges(double,double);
//out-patient
int main()
{
char patientTye;
//I = in-patient;
//O = out-patient;
int days; //num days of hospital stay
double roomRate;
//Daily room rate
double medication;
// Total medication charges
double 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
cout << "Enter I for in-patient or O for out-patient: ";
cin >> patientType;
//add code here
// Input and validate data relevant to in-patients
//add code here
// Input and validate data relevant to all patients
//add code here
// Call correct patientCharges function to return total charge
//add code here
// Display the billing statment
cout << fixed << showpoint << setprecision(2) << endl << endl;
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";
return 0;
}
//Calculate function that i have no clue how to do
[/ICODE]
•
•
Join Date: Jan 2008
Posts: 3,822
Reputation:
Solved Threads: 501
C++ Syntax (Toggle Plain Text)
#include <iostream #include <iomanip> using namespace std; //function prototypes double patientcharges(int, double, double, double); //in- patient double patientCharges(double,double); //out-patient int main() { char patientTye; //I = in-patient; //O = out-patient; int days; //num days of hospital stay double roomRate; //Daily room rate double medication; // Total medication charges double 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 cout << "Enter I for in-patient or O for out-patient: "; cin >> patientType; //add code here // Input and validate data relevant to in-patients //add code here // Input and validate data relevant to all patients //add code here // Call correct patientCharges function to return total charge //add code here // Display the billing statment cout << fixed << showpoint << setprecision(2) << endl << endl; 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"; return 0; } //Calculate function that i have no clue how to do
The coloring of the code immediately alerts you to problems.
Line 9 - doesn't start with purple, so you have forgotten the return type.
Line 31 -
cout is in blue, but for is in purple, rather than vice-versa. Almost definitely means you are missing a quotes mark in the previous line. ![]() |
Similar Threads
- having problems with code not performing the full program (C)
- Please help me figure out whats wrong with my code (C++)
- Finally Almost Finished 2 Problems!! :( (C)
- Communication Problems (Java)
- Again please someone check my code (C++)
- code problems (C++)
- Problems with displaying total payroll and allowing user to quit by entering a neg. (C++)
- need help with code (C++)
- How do you write a code which compiles in c but not in c++? (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ ftp upload directory
- Next Thread: TooTiredToSeeProblem
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






