How to put prices on tires, that user chose

I was wondering how to put values on the tires they chose, such as I want pirelli to be worth $90 so i can multiply a quantity and the price of the tire the user chose

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
  #include <iomanip>
#include <iostream>
#include <string>
#include "Tires.h"
#include "Vehicle.h"
#include "Customer.h"
#include "WinterTires.h"

using namespace std;

//Function prototypes
string goodTires();
string betterTires();
string bestTires();
string tireSize();

int main()
{
	//Declaring Variables
	string quantity;
	string typeoftire;
	string sizeoftire;
	string name;
	string phoneNumber;
	string carYear;
	string carMake;
	string carModel;


	
	int selection;
	char again = 'Y';

	cout << "//////////////////////// " << endl;
	cout << "/Welcome to Monroy tire/" << endl;
	cout << "////////////////////////\n\n" << endl;
	cout << "Enter customer information " << endl;
	cout << "Name: ";
	cin >> name;
	cout << "Phone Number: ";
	cin >> phoneNumber;
	cout << "Enter Vehicle year: ";
	cin >> carYear;
	cout << "Enter Vehicle make: ";
	cin >> carMake;
	cout << "Enter Vehicle model: ";
	cin >> carModel;

	cout << "Please select an option" << endl;
	cout << "1.Buy tires" << endl;
	cout << "2.Speak to a Manager" << endl;


	cout << "Enter you selection: ";
	cin >> selection;
	cin.clear();
	cin.ignore(numeric_limits<streamsize>::max(), '\n'); //Got this from the internet, Program did an infinite loop if I put a letter and this solved it			


	switch(selection)
	{
		case 1:
			cout << "which tires would you want" << endl;
			int tireChoice;
			cout << "1. Good ($54.00 - $75.00 each tire)" << endl;
			cout << "2. Better($70.00 - 101.00 each tire" << endl;
			cout << "3. Best ($87.00 - $115.00 each tire)" << endl;

			cout << "Enter 1 for Good, 2 for better, 3 for Best" << endl;
			cin >> tireChoice;

			//Call function based on user selection
			if (tireChoice == 1)
			{
				typeoftire = goodTires();
				sizeoftire = tireSize();
			}
			else if (tireChoice == 2)
			{
				typeoftire = betterTires();
				sizeoftire = tireSize();
			}
			else if(tireChoice == 3)
			{
				typeoftire = bestTires();
				sizeoftire = tireSize();
			}
			break;
		case 2:
			cout << "The manager will be out to attend you " << endl;
			break;
		default:
			cout << "Please select a number 1 or 2" << endl;
			break;
		
	}
	

	cout << "How many tires would you want today? ";
		cin >> quantity;

		

	Vehicle customerVehicle(carYear, carMake, carModel); //Customers Car details
	Tires customerTire(typeoftire, sizeoftire); //Customer Chosen tire
	Customer newCustomer(name, phoneNumber, customerTire, customerVehicle); //Customer's profile
	customerTire.getmanufacturer();

	system("pause");
	return 0;
}

string goodTires()
{
	int choice;
	string goodtire;
	cout << "You have chosen good, These tires are available" << endl;
	cout << "1. Veento ($54.00 each tire)" << endl;
	cout << "2. Ohtsu ($69.00 each tire)" << endl;
	cin >> choice;

	if (choice == 1)
	{
		goodtire = "Veento";
	}
	else if (choice == 2)
	{
		goodtire = "Ohtsu";
	}

	return goodtire;
		
}

string betterTires()
{
	int choice;
	string bettertire;
	cout << "You have chosen Better, These tire are available" << endl;
	cout << "1.Yokohama ($70.00 each tire)" << endl;
	cout << "2.Falken ($92.00 each tire) " << endl;
	cout << "3.Goodyear ($101.00 each tire) " << endl;
	cin >> choice;

	if (choice == 1)
	{
		bettertire = "Yohohama";
	}
	else if (choice == 2)
	{
		bettertire = "Falken";
	}
	else if (choice == 3)
	{
		bettertire = "Goodyear";
	}

	return bettertire;
}

string bestTires()
{
	double pirelli = 90.00;
	int choice;
	string besttire;
	cout << "You have chosen Best, These tires are available" << endl;
	cout << "1. Pirelli ($90.00 each tire)" << endl;
	cout << "2. Bridgestone ($100.00 each tire)" << endl;
	cout << "3. Michelin ($110.00 each tire)" << endl;
	cin >> choice;

	if (choice == 1)
	{
		besttire = "Pirelli";
	}
	else if (choice == 2)
	{
		besttire = "Bridgestone";
	}
	else if (choice == 3)
	{
		besttire = "Michelin";
	}

	return besttire;
}

string tireSize()
{
	int choice;
	string sizeTire;
	cout << "1. 215/55R17" << endl;
	cout << "2. 225/65R18" << endl;
	cout << "3. 195/45R16" << endl;
	cout << "Enter your selection: ";
	cin >> choice;

	if (choice == 1)
	{
		sizeTire = "215/55R17";
	}
	else if (choice == 2)
	{
		sizeTire = "225/65R18";
	}
	else if (choice == 3)
	{
		sizeTire = "195/45R16";
	}

	return sizeTire;

}
Last edited on
2 things

first instead of using
1
2
cin.clear();
	cin.ignore(numeric_limits<streamsize>::max(), '\n');

you should test if what they entered was valid, if not ask them to reenter a valid option

second I would just have 1 variable to take tire name, one to take price, one to take size, one to take quantity and so on, so when I go to output data its all the same variables, and if you want the total price you can just multiply quantity and tire price.

Hope this helps
Hello xmonroy,

To answer your question the simplest way would be to use a #define veento 54.00 and then @ line 118 you can change the code to be cout << "1. Veento ($" << veento << " each tire)" << endl;. The preprossor will change every occurrence of "veento" to 54.00. The drawback to this is that every time you need to change a price you will have to recompile the program.

A better option is to create a file with the names and prices and read this into the program. this way you will only have to make changes in one place and you will not have to recompile the program each time. This will be more work in the original program, but less work later on. My first thought is to read the file into a "map" to use in the program. This works best if the key portion of the map is a unique value. The value portion of the map can have duplicate information. http://www.cplusplus.com/reference/map/map/

Hope that helps

Andy
Hello xmonroy,

Sorry for the extra message, bad wifi/internet connection today.

I had a third thought for your question. You could create variables in main and pass these variables by reference to functions that would need to set a price and then in functions like after line 124 set the price for the variable passed in. Later you can use those variables defined in main in calculations or pass them to other functions like a function that writes something to the screen.

Andy
Topic archived. No new replies allowed.