943,685 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1199
  • C++ RSS
Mar 28th, 2009
0

Having problems with my code

Expand Post »
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:
// 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 patientCharges

can anyone help?
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
cassie_sanford is offline Offline
57 posts
since Oct 2008
Mar 28th, 2009
0

Re: Having problems with my code

Sorry, but it's impossible to read your snippet.
Please, use code tag properly:
[code=c++]
sources (with line breaks)
[/code]
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Mar 28th, 2009
0

Re: Having problems with my code

// 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
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
cassie_sanford is offline Offline
57 posts
since Oct 2008
Mar 28th, 2009
0

Re: Having problems with my code

Are you sure that this typo nightmare is better than previous one?
Once more:
[code=c++]
source(s) (with line breaks!!!)
[/code]
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008
Mar 29th, 2009
0

Re: Having problems with my code

[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]
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
cassie_sanford is offline Offline
57 posts
since Oct 2008
Mar 29th, 2009
0

Re: Having problems with my code

C++ Syntax (Toggle Plain Text)
  1. #include <iostream
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5.  
  6. //function prototypes
  7. double patientcharges(int, double, double, double);
  8. //in- patient double
  9. patientCharges(double,double);
  10. //out-patient
  11.  
  12.  
  13. int main()
  14. {
  15. char patientTye;
  16. //I = in-patient;
  17. //O = out-patient;
  18. int days; //num days of hospital stay
  19. double roomRate;
  20. //Daily room rate
  21. double medication;
  22. // Total medication charges
  23. double services,
  24. // Total for tests and other services
  25. totalCharges;
  26. // Total of all charges
  27. // Input and validate patient type
  28.  
  29.  
  30. cout << "This program will compute patient hospital charges
  31. cout << "Enter I for in-patient or O for out-patient: ";
  32. cin >> patientType;
  33.  
  34.  
  35. //add code here
  36. // Input and validate data relevant to in-patients
  37.  
  38.  
  39. //add code here
  40. // Input and validate data relevant to all patients
  41.  
  42.  
  43. //add code here
  44. // Call correct patientCharges function to return total charge
  45.  
  46.  
  47. //add code here
  48. // Display the billing statment
  49. cout << fixed << showpoint << setprecision(2) << endl << endl;
  50. cout << "******************************\n";
  51. if (patientType == 'I')
  52. cout << "Room charges $" << setw(8) << days*roomRate<<endl;
  53. if (services > 0.0)
  54. cout << "Lab & Services $" << setw(8) << services << endl;
  55. if (medication > 0.0)
  56. cout << "Medication $" << setw(8) << medication << endl;
  57. cout << "Total charges $" << setw(8) << totalCharges << endl;
  58. cout << "******************************\n";
  59.  
  60.  
  61. return 0;
  62. }
  63.  
  64. //Calculate function that i have no clue how to do
  65.  

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.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,372 posts
since Jan 2008
Mar 30th, 2009
0

Re: Having problems with my code

i have the source code for this. It is a basic only
if you want just leave a message..
Last edited by FrancisC07; Mar 30th, 2009 at 1:18 am. Reason: lack of info.
Reputation Points: 10
Solved Threads: 2
Light Poster
FrancisC07 is offline Offline
30 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: C++ ftp upload directory
Next Thread in C++ Forum Timeline: TooTiredToSeeProblem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC