overloaded function not working

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
119
120
121
122
123
124
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;


int bill(int);
double bill(double);


int main()
{

	// declare and initialize variables
	char choice;
	int inpatient;
	double outpatient;
	double bill = 0;
	double total = 0;
	
	cout << fixed << showpoint << setprecision(2);
	
	// displaying the menu and get a selection
	cout << "Do you want to calculate the charges for a patient's hospital stay?" << endl;
	cout << "(I) an in-patient, or ";
	cout << "(O) a out-patient? ";
	cin >> choice;

	while ( choice != 'I' && choice != 'i' &&
			choice != 'O' && choice != 'o' )
	{
		cout << "Please enter I or O: ";
		cin >> choice;
	}

	bill(inpatient);
	bill(outpatient);
	// return total for in-patient
	cout << "Total is: " << bill(inpatient);

	// return total for out-patient
	cout << "Total is: " << bill(outpatient);

	return 0;
}
	
// defintion of overloaded function bill for in-patient
int bill(int inpatient)
{

	double days;
	double rate;
	double medicine;
	double services;
	double total = 0;

	cout << "How many days did the patient spent at the hospital? ";
	cin >> days;

	while ( days <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> days;
	}

	cout << "What is the daily rate for a night at the hospital? ";
	cin >> rate;

	while ( rate <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> rate;
	}
		
	cout << "How much is for the medication charges? ";
	cin >> medicine;

	while ( medicine <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> medicine;
	}

	cout << "What is the charge for hospital services? ";
	cin >> services;

	while ( services <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> services;
	}

	total = (days * rate) + medicine + services;
	
	return total;
}
// definition of overloaded function bill for out-patient
double bill(double outpatient)
{
	double services;
	double medicine;
	double total = 0;

	cout << "What is the charge for hospital services? ";
	cin >> services;

	while ( services <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> services;
	}

	cout << "How much is for the medication charges? ";
	cin >> medicine;

	while ( medicine <= 0 )
	{
		cout << "Please enter a number greater than ZERO: ";
		cin >> medicine;
	}

	total = (services + medicine);
}
	return total;




Trying to get both Function to return their total at the same time..somehow it not working
Last edited on
In line 33 you get the user's choice but you do not act upon it.
There is no if-then to decide which function to call.

In line 36 and 37 you are calling the functions which return the total.
The only problem is that you do not assign the value which the function returns to any variable.

This leads to the fact that the function gets executed but the return value is simply lost.

And then you call the functions again. So, the user has to go through inputting the data four times instead of only once.

You have not initialized in- and outpatient.

But besides that, WHAT is not working?

int main


Topic archived. No new replies allowed.