My program skips input statement and strange compile error...

This program computes a patient's bill for a hospital stay...It is about complete except that I am getting a different compiler message.. it says that:

-first argument of 'int main(float, float, float)' should be 'int' [-Wmain],
-second argument of 'int main(float, float, float)' should be 'char **' [-Wmain],
-third argument of 'int main(float, float, float)' should probably be 'char **' [-Wmain]

Despite this it still runs however when it gets to the surgery type/cost input it skips over the input for the name of the surgery, and asks for input to surgery cost. Why is this and what do the compile warning messages me, because they obviously should be float... right?


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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//*************************************************************************************************************************************************************************
// Patient.cpp - this program computes a patient's bill for a hospital stay. The different components are as follows:													   
//		The PatientAccount class: keeps a total of the patient's charges. Also keeps track of the number of days spent in the hospital.   								   
//		The Surgery class: stores the charges for at least five types of surgery. 		*It can update the charges variable of the PatientAccount class.*				   
//		The Pharmacy class: stores the price of at least five types of medication . 	*It can update the charges variable of the PatientAccount class.*				   
// Last modified by Coy Sills on April 25th, 2014.					       									     														   
//*************************************************************************************************************************************************************************

#include <iostream>
#include <string>
using namespace std;

class PatientAccount
{
	private:
		float dailyRate;
		int patientNumber;
		int days;
		string patientName;

	public:
		PatientAccount(float, int, int, string);
		float getDailyRate();
		int getPatientNumber();
		int getDays();
		string getPatientName();
		void getPatientDisplay(float& totalCost);
};

PatientAccount::PatientAccount(float dr = 0, int pnum = 0, int dy = 0, string pn = " ")
{
	dailyRate = dr;
	patientNumber = pnum;
	days = dy;
	patientName = pn;
}

float PatientAccount::getDailyRate()
{
	cout << "Enter the daily rate for each day in the hospital: $";
	cin >> dailyRate;
	return dailyRate;
}

int PatientAccount::getPatientNumber()
{
	cout << "Enter the patients number: ";
	cin >> patientNumber;
	return patientNumber;
}

int PatientAccount::getDays()
{
	cout << "Enter the amount of days spent in the hospital: ";
	cin >> days;
	return days;
}

string PatientAccount::getPatientName()
{
	cout << "Enter the patients name: ";
	getline(cin, patientName);
	return patientName;
}

class Surgery
{
	private:
		float surgeryCost;
		string surgeryType;
		
	public:
		Surgery(float, string);
		float getCost();
		string getSurgeryType();
		void getSurgeryDisplay(float& totalCost1);
};

Surgery::Surgery(float co = 0, string st = " ")
{
	surgeryCost = co;
	surgeryType = st;
}

float Surgery::getCost()
{
	cout << "Enter the total cost of surgery: $";
	cin >> surgeryCost;
	return surgeryCost;
}

string Surgery::getSurgeryType()
{
	cout << "Enter the name of the surgery type: ";
	getline(cin, surgeryType);
	return surgeryType;
}

class Pharmacy
{
	private:
		float medCost;
		string medName;

	public:
		Pharmacy(float, string);
		float getMedCost();
		string getMedName();
		void getPharmacyDisplay(float& totalCost2);
};

Pharmacy::Pharmacy(float mc = 0, string mn = " ")
{
	medCost = mc;
	medName = mn;
};

float Pharmacy::getMedCost()
{
	cout << "Enter the cost of the medication: $";
	cin >> medCost;
	return medCost;
}

string Pharmacy::getMedName()
{
	cout << "Enter the medication name: ";
	getline(cin, medName);
	return medName;
}

void PatientAccount::getPatientDisplay(float& totalCost)
{
	PatientAccount patient(getDailyRate(), getPatientNumber(), getDays(), getPatientName());
	totalCost = days * dailyRate;

	cout << "\n";
	cout << "Patient Name:              " << patientName << endl;
	cout << "Patient Number:            " << patientNumber << endl;
	cout << "Days:                      " << days << endl;
	cout << "Daily Rate:               $" << dailyRate << endl;
	cout << "Total Cost:               $" << totalCost << endl;
	cout << "\n";
}

void Surgery::getSurgeryDisplay(float& totalCost1)
{
	Surgery patient(getCost(), getSurgeryType());
	totalCost1 = surgeryCost;
	cout << "Surgery Type:              " << surgeryType << endl;
	cout << "Surgery Cost:             $" << surgeryCost << endl;
	cout << "Total Cost:               $" << totalCost1 << endl;
	cout << "\n";
}

void Pharmacy::getPharmacyDisplay(float& totalCost2)
{
	Pharmacy patient(getMedCost(), getMedName());
	totalCost2 = medCost;
	cout << "Medication Name:           " << medName << endl;
	cout << "Medication Cost:          $" << medCost << endl;
	cout << "Total Cost:               $" << totalCost2 << endl;
	cout << "\n";
}

int main(float totalCost, float totalCost1, float totalCost2)
{
	float totalCost3;

	PatientAccount patient;
	Surgery patient1;
	Pharmacy patient2;

	patient.getPatientDisplay(totalCost);
	patient1.getSurgeryDisplay(totalCost1);
	patient2.getPharmacyDisplay(totalCost2);

	totalCost3 = ((totalCost + totalCost2) + totalCost2);
	cout << "Total Cost Hospital:     $" << totalCost3 << endl;
	cout << "\n";
	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}
Last edited on
Why is this and what do the compile warning messages me, because they obviously should be float... right?


Wrong. I don't know why you would think that. What you have is a non-standard main signature. You're not allowed to change it. What are you trying to do by passing those floats?

The standard signatures- to the best of my knowledge, are the following:

1
2
3
4
5
int main()

int main(int argc, char* argv[])

int main(int argc, char** argv)//same as previous 

Last edited on
The 3 different totals need to be summed and output in the final bill.

Would it be better to do this outside of main?
Last edited on
Well, I updated the main() parameters and declared the variables inside main instead. The program still skips over input. Why is this?

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//*************************************************************************************************************************************************************************
// Patient.cpp - this program computes a patient's bill for a hospital stay. The different components are as follows:													   
//		The PatientAccount class: keeps a total of the patient's charges. Also keeps track of the number of days spent in the hospital.   								   
//		The Surgery class: stores the charges for at least five types of surgery. 		*It can update the charges variable of the PatientAccount class.*				   
//		The Pharmacy class: stores the price of at least five types of medication . 	*It can update the charges variable of the PatientAccount class.*				   
// Last modified by Coy Sills on April 25th, 2014.					       									     														   
//*************************************************************************************************************************************************************************

#include <iostream>
#include <string>
using namespace std;

class PatientAccount
{
	private:
		float dailyRate;
		int patientNumber;
		int days;
		string patientName;

	public:
		PatientAccount(float, int, int, string);
		float getDailyRate();
		int getPatientNumber();
		int getDays();
		string getPatientName();
		void getPatientDisplay(float& totalCost);
};

PatientAccount::PatientAccount(float dr = 0, int pnum = 0, int dy = 0, string pn = " ")
{
	dailyRate = dr;
	patientNumber = pnum;
	days = dy;
	patientName = pn;
}

float PatientAccount::getDailyRate()
{
	cout << "Enter the daily rate for each day in the hospital: $";
	cin >> dailyRate;
	return dailyRate;
}

int PatientAccount::getPatientNumber()
{
	cout << "Enter the patients number: ";
	cin >> patientNumber;
	return patientNumber;
}

int PatientAccount::getDays()
{
	cout << "Enter the amount of days spent in the hospital: ";
	cin >> days;
	return days;
}

string PatientAccount::getPatientName()
{
	cout << "Enter the patients name: ";
	getline(cin, patientName);
	return patientName;
}

class Surgery
{
	private:
		float surgeryCost;
		string surgeryType;
		
	public:
		Surgery(float, string);
		float getCost();
		string getSurgeryType();
		void getSurgeryDisplay(float& totalCost1);
};

Surgery::Surgery(float co = 0, string st = " ")
{
	surgeryCost = co;
	surgeryType = st;
}

float Surgery::getCost()
{
	cout << "Enter the total cost of surgery: $";
	cin >> surgeryCost;
	return surgeryCost;
}

string Surgery::getSurgeryType()
{
	cout << "Enter the name of the surgery type: ";
	getline(cin, surgeryType);
	return surgeryType;
}

class Pharmacy
{
	private:
		float medCost;
		string medName;

	public:
		Pharmacy(float, string);
		float getMedCost();
		string getMedName();
		void getPharmacyDisplay(float& totalCost2);
};

Pharmacy::Pharmacy(float mc = 0, string mn = " ")
{
	medCost = mc;
	medName = mn;
};

float Pharmacy::getMedCost()
{
	cout << "Enter the cost of the medication: $";
	cin >> medCost;
	return medCost;
}

string Pharmacy::getMedName()
{
	cout << "Enter the medication name: ";
	getline(cin, medName);
	return medName;
}

void PatientAccount::getPatientDisplay(float& totalCost)
{
	PatientAccount patient(getDailyRate(), getPatientNumber(), getDays(), getPatientName());
	totalCost = days * dailyRate;

	cout << "\n";
	cout << "Patient Name:              " << patientName << endl;
	cout << "Patient Number:            " << patientNumber << endl;
	cout << "Days:                      " << days << endl;
	cout << "Daily Rate:               $" << dailyRate << endl;
	cout << "Total Cost:               $" << totalCost << endl;
	cout << "\n";
}

void Surgery::getSurgeryDisplay(float& totalCost1)
{
	Surgery patient(getCost(), getSurgeryType());
	totalCost1 = surgeryCost;
	cout << "Surgery Type:              " << surgeryType << endl;
	cout << "Surgery Cost:             $" << surgeryCost << endl;
	cout << "Total Cost:               $" << totalCost1 << endl;
	cout << "\n";
}

void Pharmacy::getPharmacyDisplay(float& totalCost2)
{
	Pharmacy patient(getMedCost(), getMedName());
	totalCost2 = medCost;
	cout << "Medication Name:           " << medName << endl;
	cout << "Medication Cost:          $" << medCost << endl;
	cout << "Total Cost:               $" << totalCost2 << endl;
	cout << "\n";
}

int main()
{
	
	float totalCost, totalCost1, totalCost2, totalCost3;

	PatientAccount patient;
	Surgery patient1;
	Pharmacy patient2;

	patient.getPatientDisplay(totalCost);
	patient1.getSurgeryDisplay(totalCost1);
	patient2.getPharmacyDisplay(totalCost2);

	totalCost3 = ((totalCost + totalCost2) + totalCost2);
	cout << "Total Cost Hospital:     $" << totalCost3 << endl;
	cout << "\n";
	cout << endl << "Press ENTER to exit...";
	cin.clear();
	cin.sync();
	cin.get();

	return 0;
}


Enter the patients name: John
Enter the amount of days spent in the hospital: 2
Enter the patients number: 101
Enter the daily rate for each day in the hospital: $5

Patient Name:              John
Patient Number:            101
Days:                      2
Daily Rate:               $5
Total Cost:               $10

Enter the name of the surgery type: Enter the total cost of surgery: $5
Surgery Type:
Surgery Cost:             $5
Total Cost:               $5

Enter the medication name: Enter the cost of the medication: $5
Medication Name:
Medication Cost:          $5
Total Cost:               $5

Total Cost Hospital:     $20
It's because you're mixing std::getline and std::cin (extraction operator >>).
Here's the sequence of input:

1.) Patient's name (getline)

2.) Days in hospital (cin)

3.) Patient's number (cin)

4.) Daily rate (cin)

5.) Name of the surgery (getline)

Because items 2 - 4 are integers, you have a trailing end-of-line character in the input buffer, effectively skipping the getline that follows.


*edit* I did some tests, and mysteriously I'm unable to reproduce it. I'll be back.

*edit* either way, you can try the following:

1
2
3
4
5
6
std::string Surgery::getSurgeryType() {
	std::cin.ignore(std::numeric_limits<std::streamsize>::max());
	std::cout << "Enter the name of the surgery type: ";
	std::getline(std::cin, surgeryType);
	return surgeryType;
}


Don't forget to include:

#include <limits>

And define the following before your includes:

#define NOMINMAX
Last edited on
Should I use one or the other then? It was my understanding you use the getline for string inputs and cin for integer inputs...
However, i did read in the tutorial on the site,
Therefore, unless you have a strong reason not to, you should always use getline to get input in your console programs instead of extracting from cin.
(http://www.cplusplus.com/doc/tutorial/basic_io/)

Additional explanation on this would be most helpful.


*EDIT:
Adding the cin.ignore(std::numeric_limits<std::streamsize>::max()); gave an infinite loop of input. In addition, I had to put it after the output statement not before, such as you have it above - otherwise the user would have no instruction other than a blinking cursor...
Last edited on
Sorry that it didn't work.
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
float PatientAccount::getDailyRate()
{
	cout << "Enter the daily rate for each day in the hospital: $";
	cin >> dailyRate;
	std::cin.ignore();
	return dailyRate;
}

int PatientAccount::getPatientNumber()
{
	cout << "Enter the patients number: ";
	cin >> patientNumber;
	std::cin.ignore();
	return patientNumber;
}

int PatientAccount::getDays()
{
	cout << "Enter the amount of days spent in the hospital: ";
	cin >> days;
	std::cin.ignore();
	return days;
}

You can remove the #include <limits> and the #define NOMINMAX

Additional explanation on this would be most helpful.

Unfortunately, I'm not super smart when it comes to that. All I can do is redirect you to some semi-relevant threads and hope they're helpful:

http://stackoverflow.com/questions/11462021/issue-with-cin-when-spaces-are-inputted-using-string-class

http://stackoverflow.com/questions/2765462/how-to-cin-space-in-c

http://www.cplusplus.com/forum/articles/6046/
Last edited on
Topic archived. No new replies allowed.