I cannot seem to locate the problem in my code. I constantly get the error "fatal error C1075: end of file found before the left brace '{'" and it refers to line 90.
// Header files section
#include <iostream>
usingnamespace std;
// Function prototypes
double getTotalCharges(int, double, double, double);
double getTotalCharges(double, double);
// start main function
int main()
{
//Declare variables
int typeOfPatient, numberOfDays;
double dailyRate, medicationCharges, serviceCharges;
double totalCharges;
// Prompt the user for type of patient
cout << "Enter the type of patient (1 for in-patient or 2 for out-patient): ";
cin >> typeOfPatient;
// Verify whether the type of patient is valid
while(typeOfPatient != 1 && typeOfPatient != 2)
{
cout << "Enter the type of patient (1 for in-patient or 2 for out-patient): ";
cin >> typeOfPatient;
} // end while statement
//Prompt the user for hospital medication charges
cout << "Enter the hospital medication charges: ";
cin >> medicationCharges;
/* Verify whether the hospital medication charges are negative */
while(medicationCharges < 0)
{
cout << "Enter the hospital medication charges: ";
cin >> medicationCharges;
/* Verify whether the hospital medication charges are negative */
while(medicationCharges < 0)
{
cout << "Enter the hospital medication charges: ";
cin >> medicationCharges;
} //end while
//prompt the user for hospital service charges
cout << "Enter the hospital service charges: ";
cin >> serviceCharges;
/* Verify whether the hospital service charges are negative */
while(serviceCharges < 0)
{
cout << "Enter the hospital service charges: ";
cin >> serviceCharges;
} //end while
//Verify whether the type of patient is in-patient
if(typeOfPatient==1)
{
/* Prompt the user for number of days patient spent */
cout << "Enter the number of days spent by patient in the hospital:";
cin >> numberOfDays;
//Verify whether the number of days is negative
while(numberOfDays < 0)
{
cout << "Enter the number of days spent by patient in the hospital:";\
cin>>numberOfDays;
} // end while
// Prompt the user for daily rate
cout << "Enter the daily rate in the hosptal:";
cin >>dailyRate;
//Verify whether the daily rate is negative
while(dailyRate < 0)
{
cout << "Enter the daily rate in the hospital: ";
cin >> dailyRate;
} // endwhile
// Get the total charges
totalCharges = getTotalCharges(numberOfDays, dailyRate, medicationCharges, serviceCharges);
}
else // if the type of patient is out-patient
totalCharges = getTotalCharges(medicationCharges, serviceCharges);
// Display the total hospital charges
cout << "The hospital charges for the patient are: $" << totalCharges << endl;
// pause the system for a while
system("pause");
return 0;
} // end of main function
Finding a missing brace in such a long main function is difficult. It's much better practice to divide your program into functions, they make the whole code easier to read.
// Header files section
#include <iostream>
usingnamespace std;
double getTotalCharges(int numberOfDays, double dailyRate,
double medicationCharges, double serviceCharges)
{
return numberOfDays * dailyRate + medicationCharges + serviceCharges;
}
double getTotalCharges(double medicationCharges, double serviceCharges)
{
return medicationCharges + serviceCharges;
}
int getPatientType()
{
int typeOfPatient;
cout << "Enter the type of patient (1 for in-patient or 2 for out-patient): ";
cin >> typeOfPatient;
// Verify whether the type of patient is valid
while (typeOfPatient != 1 && typeOfPatient != 2)
{
cout << "Enter the type of patient (1 for in-patient or 2 for out-patient): ";
cin >> typeOfPatient;
} // end while statement
return typeOfPatient;
}
double getMedicationCharges()
{
double medicationCharges;
cout << "Enter the hospital medication charges: ";
cin >> medicationCharges;
/* Verify whether the hospital medication charges are negative */
while (medicationCharges < 0)
{
cout << "Enter the hospital medication charges: ";
cin >> medicationCharges;
}
return medicationCharges;
}
double getServiceCharges()
{
double serviceCharges;
cout << "Enter the hospital service charges: ";
cin >> serviceCharges;
/* Verify whether the hospital service charges are negative */
while (serviceCharges < 0)
{
cout << "Enter the hospital service charges: ";
cin >> serviceCharges;
} //end while
return serviceCharges;
}
int getNumberOfDays()
{
int numberOfDays;
/* Prompt the user for number of days patient spent */
cout << "Enter the number of days spent by patient in the hospital:";
cin >> numberOfDays;
//Verify whether the number of days is negative
while (numberOfDays < 0)
{
cout << "Enter the number of days spent by patient in the hospital:"; \
cin >> numberOfDays;
} // end while
return numberOfDays;
}
double getDailyRate()
{
double dailyRate;
cout << "Enter the daily rate in the hosptal:";
cin >> dailyRate;
//Verify whether the daily rate is negative
while (dailyRate < 0)
{
cout << "Enter the daily rate in the hospital: ";
cin >> dailyRate;
} // endwhile
return dailyRate;
}
int main()
{
double totalCharges;
int typeOfPatient = getPatientType();
double medicationCharges = getMedicationCharges();
double serviceCharges = getServiceCharges();
//Verify whether the type of patient is in-patient
if (typeOfPatient == 1)
{
int numberOfDays = getNumberOfDays();
double dailyRate = getDailyRate();
totalCharges = getTotalCharges(numberOfDays, dailyRate,
medicationCharges, serviceCharges);
}
else // if the type of patient is out-patient
{
totalCharges = getTotalCharges(medicationCharges,
serviceCharges);
}
// Display the total hospital charges
cout << "The hospital charges for the patient are: $" << totalCharges << endl;
// pause the system for a while
system("pause");
return 0;
} // end of main function