Overloading Functions Help [Else If Statement]

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.
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
#include <iostream>
#include <cstdlib>
#include <iomanip>
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
1
2
3
4
5
6
7
8
if (Choice == 1); //<-- bad!
{
    //...
}
else if (Choice == 2); //<-- bad!
{
    //...
}
is the same as
1
2
3
4
5
6
7
8
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.