Hello. I got a small problem, as is expected here I assume haha. So this just tells me I have an "else without a previous if", but there's an if right there. I can't pinpoint where I'm going wrong, because all the examples look the same as this. So I'm clueless.

Here's the program, it asks if they were an in-patient, or out-patient. Then some questions, and finally it outputs a total cost.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` ``````#include #include #include using namespace std; double Patient(int Days, double DailyRate, double Charges, double MedicationCharges); double Patient(double Charges, double MedicationCharges); int main() { //Variables: int Days = 0, Choice = 0; double DailyRate = 0, Charges = 0, TotalInPatient = 0, TotalOutPatient = 0, MedicationCharges = 0; //Start: cout << "Enter 1 if they were an In-Patient, enter 2 if they were an Out-Patient" << endl; cin >> Choice; if (Choice == 1); { cout << "How many days were spent in the hosptial?" << endl; cin >> Days; cout << "What was the daily rate?" << endl; cin >> DailyRate; cout << "What were the charges for the visit?" << endl; cin >> Charges; cout << "What were the medication charges?" << endl; cin >> MedicationCharges; TotalInPatient = Patient(Days, DailyRate, Charges, MedicationCharges); cout << fixed << showpoint << setprecision(2); cout << "The total is: \$" << TotalInPatient << endl; exit(0); } else if (Choice == 2); { cout << "What were the charges for the visit?" << endl; cin >> Charges; cout << "What were the medication charges?" << endl; cin >> MedicationCharges; TotalOutPatient = Patient(Days, DailyRate, Charges, MedicationCharges); cout << fixed << showpoint << setprecision(2); cout << "The total is: \$" << TotalOutPatient << endl; exit(0); } } //In-Patient Data: double Patient(int Days, double DailyRate, double Charges, double MedicationCharges) { return ((Days * DailyRate) + Charges + MedicationCharges); } //Out-Patient Data: double Patient(double Charges, double MedicationCharges) { return (Charges + MedicationCharges); }``````
Don't put semi-colons at the end of conditional statements. Your code
 ``12345678`` ``````if (Choice == 1); //<-- bad! { //... } else if (Choice == 2); //<-- bad! { //... }``````
is the same as
 ``12345678`` ``````if (Choice == 1){} { //unconditional } else if (Choice == 2){} { //unconditional }``````
Oh, so it was ending it before it even checked the if statements... Oops, haha. Another lesson learned. Thank you.
Topic archived. No new replies allowed.