I want to use "enter" key to dispense gas.

I want to use "enter" key to dispense gas........
How do I do that instead of an integer.....

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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
  #pragma once
//#pragma once
#include <iostream>
using namespace std;
//#ifndef _GasPump
//#define _GasPump
class GasPump
{

private:
	double CostPerGallon; // one grade of gas at cost per gallon
	double AmountGas;        // Amount of gas dispensed per session  
	double ChargeGas;		// Charge for gas dispenseed per fueling session
	double TotalGas;		// Toal amount of gas sold
	static double m;



public:
	GasPump(double price);
	GasPump();
	void AmountGasPrint();		 // Fn to display the amount gas dispensed
	void ChargeGasPrint();		// Fn to display amount charge for gas dispensed
	void CostPerGallonPrint();	// Fn to display the cost per gallon
	void ChangeGallonPrint(double price);	// Fn to change price per gallon at pump
	void ResetPump();				// Fn to reset the amount dispensed and ** amonut charged
	void TotalGasPrint();   // Fn to 
	void AmountGasPrint(int x); // Fn to overload "AmountGasPrint()" which do not take any parameters
	static void FillMain(double); // Static Fn to fill main tank
	static double RemainingMainTank(); //Static Fn to 
	void everthingPrint();   //to print total after static variable implemented

};

double GasPump::m = 100;

//#endif;

//#include "GasPump.h"
//#include <iostream>
//using namespace std;



GasPump::GasPump()
{

	CostPerGallon = 3.95;
	AmountGas = 0;
	ChargeGas = 0;
	TotalGas = 0;
}


GasPump::GasPump(double price)
{

	CostPerGallon = price;
	AmountGas = 0;
	ChargeGas = 0;
	TotalGas = 0;
}


void GasPump::AmountGasPrint() {

	cout << "Amount of Gas Dispensed" << AmountGas << endl;

}

void GasPump::ChargeGasPrint() {

	cout << "Amount Charge for Gas Dispensed" << ChargeGas << endl;
}

void GasPump::CostPerGallonPrint() {
	cout << "Service Gasoline Price is " << CostPerGallon << "  per gallon" << endl;

}

void GasPump::ChangeGallonPrint(double price) {
	CostPerGallon = price;
}

void GasPump::ResetPump() {
	AmountGas = 0;
	ChargeGas = 0;

}


void GasPump::TotalGasPrint() {
	cout << "Your total $" << TotalGas << endl;

}


void GasPump::AmountGasPrint(int x) {  // Overload calling

	cout << " Pumping gas ..." ;

	int y = 0;

	while (y != x) {

		AmountGas = AmountGas + 0.1;
		ChargeGas = AmountGas * CostPerGallon;
		TotalGas += AmountGas;
		m -= TotalGas;

		AmountGasPrint();
		ChargeGasPrint();
		TotalGasPrint();

		cout << "Enter " << x << " to quit." << endl;

		cout << "or Enter any other number " << x << " to continue." << endl;

		cin >> y;

		if (m == 0) {

			y = x;
			cout << "Error main tank is empty" << endl;

		}



	}
}


void GasPump::FillMain(double y) { // Static Fn to fill main tank

	m = y; //passing the argument. 

}

double  GasPump::RemainingMainTank() { //Static Fn to

	return   m;
}
//
//	 void GasPump::everthingPrint() {
//		 TotalGasPrint();
//		 cout << "Main Gas" << RemainingMainTank() << endl;
//	 }

#include "GasPump.h"




GasPump::GasPump()
{

	CostPerGallon = 3.95; 
	AmountGas = 0;        
	ChargeGas = 0;		
	TotalGas = 0;
}


GasPump::GasPump(double price)
{

	CostPerGallon = price;
	AmountGas = 0;
	ChargeGas = 0;
	TotalGas = 0;
}


void GasPump::AmountGasPrint() {

	cout << "Amount of Gas Dispensed" << AmountGas << endl;

}

void GasPump::ChargeGasPrint() {

	cout << "Amount Charge for Gas Dispensed" << ChargeGas << endl;
}

void GasPump::CostPerGallonPrint() {
	cout << "Service Gasoline Price is " << CostPerGallon << "  per gallon" << endl;

}

void GasPump::ChangeGallonPrint(double price) {
	CostPerGallon = price;
}

void GasPump::ResetPump() {
	AmountGas = 0;
	ChargeGas = 0;

}


void GasPump::TotalGasPrint() {
	cout << "Your total $" << TotalGas << endl;

}


void GasPump::AmountGasPrint(int x) {  // Overload calling

	cout << "Press" << x << " to quit....." << endl;

	int y = 0;

	while (y != x) {

		AmountGas = AmountGas + 0.1;
		ChargeGas = AmountGas * CostPerGallon;
		TotalGas += AmountGas;
		//mainGasTank -= TotalGas;

		AmountGasPrint();
		ChargeGasPrint();
		TotalGasPrint();

		cout << "Press" << x << " to quit....." << endl;

		cin >> y;

		/*if (mainGasTank == 0)
			y = x ;*/
		


	}
}


	//	 void GasPump:: FillMain(double y) { // Static Fn to fill main tank

	//		mainGasTank = y; //passing the argument. 

	//}
	////	  double  GasPump:: RemainingMainTank() { //Static Fn to

	////		 return   mainGasTank;
	////}
	//
	//	 void GasPump::everthingPrint() {
	//		 TotalGasPrint();
	//		 cout << "Main Gas" << RemainingMainTank() << endl;
	//	 } 
Last edited on
Hello Jaycode365,

Welcome to the forum.

Where is the main function? What drives the class and how does it get started?

If one of the member functions is in need of using the "enter" key to start something it would help if you would point it out.

There is not quite enough information for me to figure out what to do. Maybe after I see how everything works better, but I am thing that it would be some place in main for what you want.

Hope that helps,

Andy
#include "GasPump.h"
#include <iostream>
using namespace std;


int main() {

GasPump pump1; //Default Construtor no parameters
cout << " Gas Pump Modeling Program" << endl;

//GasPump pump2(2.00); // Contructor taking one argument as parmeter
cout << "Full ";
pump1.CostPerGallonPrint();

GasPump pump2(2.50);
cout << "Self ";
pump2.CostPerGallonPrint();

// pump1.AmountGasPrint(11);

system("pause");
return 0;

}
Hello Jaycode365,

Thank you for the code in main.

I am still not sure where you might "pressing to start something".

I am thing that in main you show the user the price for "Full" ans "Self" and should give the user an opportunity to choose which price then call the appropriate function.

In the "pump?.Amount GasPrint" function there are some problems. to start with:
[codevoid GasPump::AmountGasPrint(int x)][/code] I believe that "x" would work better as a double and "y" also. Inside the while loop you do nothing to increase the value of "y" unless "m == 0" and sets "y" = "x" then the while loop would end and technically you would have pumped more then the tank you are trying to fill.

I also noticed that "TotalGas" was not coming up with the correct amount.

The two prompts do not make any sense. std::cout << "\nEnter " << x << " to quit." << std::endl;. You are using the value of "x" in this prompt which comes out as "Enter 11 to quit" and the following line is saying "Enter 11 to continue". You can not have it both ways. I am not even sure why you want the value of "x" there in the first place? Notice that a spaces in the quoted string before and after "x" makes it easier to read. The "\n" at the beginning helps to break up what is sent to the screen so you do not have line after line all run together.

I put a comment on the "cin" just to make things go a little faster. Even with it there I do not understand the need for it.

Your next function:
1
2
3
4
void GasPump::FillMain(double y) // Static Fn to fill main tank
{ 
	m = y; //passing the argument. 
}

I have not progressed far enough to get to this function, but I am having a hard time understanding how it works and what it is meant to do.

The next problem I had was with the use of "static" in the class. No matter what I tried I could not make it work, but I do not believe it is need in the first place. Still looking into that.

Once I removes all occurrences of "static" the program compiled and ran for me. I still have to figure out what is happening with:
1
2
3
4
AmountGas = AmountGas + 0.1;
ChargeGas = AmountGas * CostPerGallon;
TotalGas += AmountGas;
m -= TotalGas;

It looks like "TotalGas" should equal the value of "x" when it is finished. As I recall that is not what I saw on the screen.

I want to try some different things today and see what I get. I will let you know when I have something.

Hope that helps,

Andy
Topic archived. No new replies allowed.