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
|
/*
PROGRAM: HOSPITAL.CPP
Written by
This program uses functions and calculates the total cost of a hospital bill after the user inputs their hospital information.
Assignment number 7
*/
#include <iostream>
#include <string>
using namespace std;
// Function prototypes
int getPositiveInt( string );
double getMoney ( string );
double calculateTotal(int, double, double, double) ;// Inpatient
double calculateTotal(double, double);// Outpatient
int main()
{
int menuchoice;
int days; // number of days
double roomRate, // Daily room rate
medication, // Total medication charges,
services, // Total for tests and other services,
total;
//Display munuchoice
// Input and validate patient type
cout << "This program will compute patient hospital charges.\n";
cout << "You need a the doctor yo. What kind of patient are you?" << endl;
cout << " 1) Inpatient. " << endl;
cout << " 2) Outpatient. " << endl;
cout << " 3) Leaving. " << endl;
if ( menuchoice == 1)
{
days = getPositiveInt( "Enter how long you stay in the hospital:\n " );
roomRate = getMoney( "Enter your room charge:\n " );
medication = getMoney( "Enter the cost of your medication:\n " );
services = getMoney( "Enter the cost of the hospital services: " );
total = calculateTotal( days, roomRate, medication, services );
}
else if (menuchoice == 2 )
{
medication = getMoney( "Enter the cost of your medication:\n " );
services = getMoney( "Enter the cost of the hospital services: " );
total = calculateTotal( medication, services );
}
else (menuchoice == 3);
{
cout << " Thank you for leaving the Hospital." << endl;
}
system( "pause" );
return 0;
} // main()
int getChoice();
{
int input;
cin >> input;
}
int getPositiveInt( string prompt )
{
int input;
do
{
cout << prompt;
// While you try to read an integer and FAIL
while ( ! ( cin >> input ) )
{
// Clear the error condition of failing to read an int
cin.clear();
// Ignore 1 character, up to a \n
cin.ignore( 1, '\n' );
} // while
} while ( input <= 0 );
return input;
} // getPositiveInt()
double getMoney( string prompt )
{
int input;
do
{
cout << prompt;
// While you try to read an integer and FAIL
while ( ! ( cin >> input ) )
{
// Clear the error condition of failing to read an int
cin.clear();
// Ignore 1 character, up to a \n
cin.ignore( 1, '\n' );
} // while
} while ( input < 0 );
return input;
} // getPositiveInt()
|