Use of functions in main with sentinel loop

I need this program to run a loop in the main and use the value E as a sentinel, But I need to use functions. I am confused on how to run the loop in the main and put it in the proper order.

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

void InputInitialData(int& currentYear, double& gasPrice);
void InputUserData(string& carManufacture, string& carModel, int& carYear, int& carTankCapacity, int& carMPG, string& carFullName, int& carAge, int currentYear, double& carCruiseRange);
void FindHighMilesCar(string& highMPGName, int& highMPG, int carMPG, string carFullName);
void FindHighCrusingRange(string& highCruiseName, int& highCruiseRange, int carCruiseRange, string carFullName);
void FindLowCostCar(string& lowCostName, int& lowCostToDrive, int carMPG, double gasPrice, string carFullName);
void OutputCarData(string carManufacture, string carModel, int carAge, int carTankCapacity, double gasPrice, double carCruiseRange, double carCostLongDrive);
void OutputCarStats(string highMPGName, int highMPG, string highCruiseName, int highCruiseRange, string lowCostName, int lowCostToDrive);

int main()
{
	string		carManufacture,
		carModel,
		carFullName,
		highMPGName,
		highCruiseName,
		lowCostName;

	const	string SENTINEL;

	int		numberToCompare = 0,
		count = 0,
		currentYear = 0,
		carYear = 0,
		carAge = 0,
		carTankCapacity = 0,
		carMPG = 0,
		averageMPG = 0,
		highMPG = -1,
		highCruiseRange = -1,
		lowCostToDrive = 10000;

	double		gasPrice = 0.0,
		carCruiseRange = 0.0,
		carCostLongDrive = 0.0;


	cout << "Vehicle Comparison Report\n\n";

	InputInitialData(currentYear, gasPrice);


	while (carManufacture != SENTINEL)

	{
		InputUserData(carManufacture, carModel, carYear, carTankCapacity, carMPG, carFullName, carAge, currentYear, carCruiseRange);
	}
		FindHighMilesCar(highMPGName, highMPG, carMPG, carFullName);
		FindHighCrusingRange(highCruiseName, highCruiseRange, carCruiseRange, carFullName);
		FindLowCostCar(lowCostName, lowCostToDrive, carMPG, gasPrice, carFullName);
		OutputCarData(carManufacture, carModel, carAge, carTankCapacity, gasPrice, carCruiseRange, carCostLongDrive);
		OutputCarStats(highMPGName, highMPG, highCruiseName, highCruiseRange, lowCostName, lowCostToDrive);

	return 0;
}

// Input Intial Data Defintion
void InputInitialData(int& currentYear, double& gasPrice)
{
	cout << "\nEnter the current year: ";
	cin >> currentYear;
	cout << "\nWhat is the current gasoline price in your area? $";
	cin >> gasPrice;
	system("cls");

}

// Input User Data Defintion
void InputUserData(string& carManufacture, string& carModel, int& carYear, int& carTankCapacity, int& carMPG, string& carFullName, int& carAge, int currentYear, double& carCruiseRange)
{
	const	string SENTINEL = "E";

	cout << "Please enter the vehicle\'s manufacturer: ";
	cin >> carManufacture;
	cout << "\nPlease enter the vehicle model: ";
	cin >> carModel;
	cout << "\nEnter the vehicle\'s year of manufacture: ";
	cin >> carYear;
	cout << "\nEnter the vehicle\'s listed MPG: ";
	cin >> carMPG;
	cout << "\nEnter the vehicle's gas tank capacity: ";
	cin >> carTankCapacity;

	system("cls");


	carFullName = carManufacture + " " + carModel;
	carAge = currentYear - carYear;
	carCruiseRange = carTankCapacity * carMPG;
}

	//Find High Miles Car Defintion
	void FindHighMilesCar(string& highMPGName, int& highMPG, int carMPG, string carFullName)
	{

		if (carMPG > highMPG)
		{
			highMPGName = carFullName;
			highMPG = carMPG;
		}

	}

	//Find High Crusing Range Defintion
	void FindHighCrusingRange(string& highCruiseName, int& highCruiseRange, int carCruiseRange, string carFullName)
	{

		if (carCruiseRange > highCruiseRange)
		{
			highCruiseName = carFullName;
			highCruiseRange = carCruiseRange;
		}
	}

	//Find Low Cost Car Defintion
	void FindLowCostCar(string& lowCostName, int& lowCostToDrive, int carMPG, double gasPrice, string carFullName)
	{
		const	int	LONG_DISTANCE_MILES = 500;
		double carCostLongDrive;

		carCostLongDrive = static_cast<double>((LONG_DISTANCE_MILES) / static_cast<double>(carMPG)) * gasPrice;

		if (carCostLongDrive < lowCostToDrive)
		{
			lowCostName = carFullName;
			lowCostToDrive = carCostLongDrive;
		}
	}

	// Output Car Data Defintion 
	void OutputCarData(string carManufacture, string carModel, int carAge, int carTankCapacity, double gasPrice, double carCruiseRange, double carCostLongDrive)
	{
		cout << "Vehicle Comparison Report\n\n";
		cout << "\tVehicle under consideration: " << carManufacture << " " << carModel;
		cout << "\n\n\tAge of vehicle: " << carAge;
		cout << "\n\tVehicle gas tank capacity: " << carTankCapacity;
		cout << "\n\tVehicle cruising range: " << carCruiseRange;
		cout << "\n\tCurrent gasoline price: $" << gasPrice;
		cout << "\n\tCost to drive 500 miles based on MPG and gas price: $" << carCostLongDrive << "\n\n";
		system("pause");
		system("cls");
	}

	// Output Car Stats 
	void OutputCarStats(string highMPGName, int highMPG, string highCruiseName, int highCruiseRange, string lowCostName, int lowCostToDrive)
	{
		cout << "Vehicle Comparison Report\n\n";

		cout << "Average MPG of vehicles compared: " << highMPGName;
		cout << "\n\nVehicle with highest MPG: " << highMPGName;
		cout << "\nHighest MPG: " << highMPG;
		cout << "\n\nVehicle with highest cruising range: " << highCruiseName;
		cout << "\nHighest cruising range: " << highCruiseRange;
		cout << "\n\nVehicle with lowest cost to drive 500 miles: " << lowCostName;
		cout << "\nCost to drive 500 miles: $" << lowCostToDrive;
	}
it looks like you want something like this in main

selection = "X";
while(selection != 'E') //or "E"?
{
cout << enter selection;
cin >> selection;
if(selection == something)
call one function();
else if (selection == other)
call other function();
... more else/ifs
if "E" do nothing, and the while will stop for you.
}

Topic archived. No new replies allowed.