I'm supposed to make a hospital program.

It keeps pointing to line 26. Did i forget to declare something?

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
 #include <iostream>
using namespace std;

    void answer(char &);
    char getPatientType();
    double patientCharges(int, double, double, double); 
    double patientCharges(double, double); 


int main()

{
    char selection;
    int days;
    double rate;
    double charges;
    double medicine;


    cout << "is the patient an 'in-patient' or an 'out-patient'? Type 'I' for in patient or 'O' for out patient."<< endl;
    cin >> selection;
    
    
    switch (selection)
    {
           case 'I';
    case 'I' cout<< "How many days did you spend in the hospital?"<< endl;
    cin >> days;
    cout << "what is the daily rate?"<< endl;
    cin >> rate;
    cout<< "hospital charges"<< endl;
    cin>>charges;
    cout<< "please enter medicine charges"<< endl;
    cin >> medicine;
    cout << calctotal(days, rate, medcine, charges)<< endl;
    
    case 'O';
    cout<< "charges by the hospital"<< endl;
    cin>> charges;
    cout<<"medicine charges"<< endl;
    cin>>medicine;
    cout<< calctotal(charges, medicine);
    
    }


switch (selection)
    

		system("pause");
		return 0;
    }

 
The program is saying that i forgot a ";" but i dont see anything.
you have twice
case 'I'
the compiler doesn't like that at all

on top of that

1
2
case 'I': // <-- colon not semicolon
case 'O': // <-- same here 


aaand don't forget "break" at the end:

1
2
3
case 'I': { //some code
break; //without this your programm will execute whatever code comes after "case 'O':" as well (doesn't matter if the character was 'I')
}
Last edited on
now it is saying that medicine is not declared but it obviously is.
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
    switch (selection)
    {
   //        case 'I'; // remove this
    case 'I': { //added here ":" and "{"
 cout<< "How many days did you spend in the hospital?"<< endl;
    cin >> days;
    cout << "what is the daily rate?"<< endl;
    cin >> rate;
    cout<< "hospital charges"<< endl;
    cin>>charges;
    cout<< "please enter medicine charges"<< endl;
    cin >> medicine;
    cout << calctotal(days, rate, medcine, charges)<< endl;
    break; //added here break;
} //added here "}"     between {} was now your code block when your character is 'I'
    case 'O': {  // changed ; to : and added "{"
    cout<< "charges by the hospital"<< endl;
    cin>> charges;
    cout<<"medicine charges"<< endl;
    cin>>medicine;
    cout<< calctotal(charges, medicine);
break; // added break; (wasn't necessary because there isn't anything following that blockcode inside the switch statement anyway)
} // added "}"  => betwee these {} is your codeblock for "case 'O'"
    
    }


//switch (selection)  //remove this 
okay i think i fixed everything, the last thing its telling me is that i have an "undefined reference to calctotal" what is that?
well you seem to be calling a function called "calctotal" that doesn't exist (if the code you posted is everything you have then it really doesn't exist)
=> you have to declare the function and program whatever it is supposed to do.
Last edited on
well i put this at the header.
double calctotal(int, double, double, double);
double calctotal(double, double);
these are declarations that still require a definition

Below is what's missing: (the Definition)
1
2
3
double calctotal(double x, double y) {
// code whatever the function is supposed to do
}
double calctotal(int, double, double, double);{(int days* double rate)+ double charges+ double medicine
}
double calctotal(double, double); {double charges+ double medicine} am i supposed to do it like this? its still giving me problems.
I'll give u the code for one of them:

1
2
3
4
double calctotal(double charges, double medicine) 
{
return charges + medicine;
}


You pass your values charges and medicine to the function
you add them
and return the result to whereever you called the function from
Last edited on
Topic archived. No new replies allowed.