Online shopping market- Car dealership

Guys, there's a problem with showing the value of the float.
also, I have to repeat the code if needed then I can't finish the code it always repeated. I hope you guys help me with this problem

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
// GROUP 3 
// ICT-2

#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;

int main() {
	float Camry, Corolla_Altis, Vios, Wigo, Yaris, Corolla_Cross, FJ_Cruiser, Fortuner, Land_Cruiser,Average;
	float Honda_Accord, Honda_Accord_Hybrid, Honda_Civic, Honda_Clarity, Honda_CR_V, Honda_HR_V, Honda_Insight, Honda_Odyssey;
	char Order_again, Yes_or_No;
	int Cars;
	bool YesOrNo;
	do{
	
	cout << "Online Car Dealership" << endl;
	cout << "Please Select the type Car: " << endl;
     // TOYOTA CARS
	cout << "Toyota Cars: "<< endl;
	cout << "1. Camry" << endl;
	cout << "2. Corolla Altis" << endl;
	cout << "3. Vios" << endl;
	cout << "4. Wigo" << endl;
	cout << "5. Yaris" << endl;
	cout << "6. Corolla Cross" << endl;
	cout << "7. FJ Cruiser" << endl;
	cout << "8. Fortuner" << endl;
	cout << "9. Land Cruiser" << endl;
     // HONDA CARS
	cout << "Honda Cars: " << endl;
	cout << "10. Accord" << endl;
	cout << "11. Accord Hybrid" << endl;
	cout << "12. Civic" << endl;
	cout << "13. Clarity" << endl;
	cout << "14. CR-V" << endl;
	cout << "15. HR-V" << endl;
	cout << "16. Insight" << endl;
	cout << "17. Odyssey" << endl;
	cout << "Input Number According to the type of Car: ";
    cin >> Cars;
   switch (Cars)
   {
   	case 1:
   		Camry = 2042000;
   		cout << "You Selected Camry" << Camry << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Camry";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 2:
   		Corolla_Altis = 1595000;
   		cout << "You Selected Corollla Atlis" << Corolla_Altis << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Corolla Altis";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 3:
   		Vios = 1056000;
   		cout << "You Selected Vios" << Vios << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Vois";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 4:
   		Wigo = 700000;
   		cout << "You Selected Wigo" << Wigo << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Wigo";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 5:
   		Yaris = 1065000;
   		cout << "You Selected Yaris" << Yaris << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Yaris";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 6:
   		Corolla_Cross = 1650000;
   		cout << "You Selected Corolla Cross" << Corolla_Cross << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Coro;;a Cross";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 7:
   		FJ_Cruiser = 2083000;
   		cout << "You Selected FJ Cruiser" << FJ_Cruiser << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered FJ Cruiser";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 8:
   		Fortuner = 2414000;
   		cout << "You Selected Fortuner" << Fortuner << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Fortuner";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 9:
   		Land_Cruiser = 4950000;
   		cout << "You Selected Land_Cruiser" << Land_Cruiser << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Land_Cruiser";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 10:
   		Honda_Accord = 24270;
   		cout << "You Selected Honda Accord" << "$" << Honda_Accord << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Accord";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }   
    case 11:
   		Honda_Accord_Hybrid = 25870;
   		cout << "You Selected Honda Accord Hybrid" << "$" << Honda_Accord_Hybrid << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Accord Hybrid";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 12:
   		Honda_Civic = 20000;
   		cout << "You Selected Honda Civic" << "$" << Honda_Civic << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Civic";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 13:
   		Honda_Clarity = 36620;
   		cout << "You Selected Honda Clarity" << "$" << Honda_Clarity << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Clarity";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 14:
   		Honda_CR_V = 25150;
   		cout << "You Selected Honda CR V" << "$" << Honda_CR_V << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda CR V";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }
	case 15:
   		Honda_HR_V = 20920;
   		cout << "You Selected Honda HR V" << "$" << Honda_HR_V << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda HR V";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }  
    case 16:
   		Honda_Insight = 22930;
   		cout << "You Selected Honda Insight" << "$" << Honda_Insight << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Insight";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   		    break;	
		   }
		   
	case 17:
   		Honda_Odyssey = 30790;
   		cout << "You Selected Honda Odyssey" << "$" << Honda_Odyssey << endl << "To be Comformed Type y Yes, if type n if No: ";
   		cin >> Yes_or_No;
   		if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Odyssey";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
		   }     
	}    
	cout << "Do you want to order again? type y if Yes, type n if No";
	cin >> Order_again;
} 

    while (Order_again = 'y');
	return 0;
}

also my teacher recomend me to use array but im not relly fluent to use it.
thats he's clue to solve this.
Last edited on
> Guys, there's a problem with showing the value of the float.
Yeah, we don't use floating point for money.

> also, I have to repeat the code if needed then I can't finish the code it always repeated.
You have = where you should have == in your if and while tests.

> also my teacher recomend me to use array but im not relly fluent to use it.
Here is an example.
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
// Example program
#include <iostream>
#include <string>

void display_menu(const std::string &manufacturer,
                  const std::string names[],
                  const int prices[],
                  const size_t numCars ) {
  std::cout << manufacturer << " Cars\n";
  for ( size_t i = 0 ; i < numCars ; i++ ) {
    std::cout << i + 1
              << ". "
              << names[i]
              << " for "
              << prices[i]
              << " yen\n";
  }
}

int main()
{
  // std::vector would be better than arrays
  // a structure containing both the name and price together would be better
  std::string toyota_car_names[] = {
    "Camry",
    "Corolla Altis",
    "Vios",
    "Wigo",
    "Yaris",
    "Corolla Cross",
    "FJ Cruiser",
    "Fortuner",
    "Land Cruiser",
  };
  int toyota_car_prices[] = {
    2042000,
    1595000,
    1056000,
    700000,
    1065000,
    1650000,
    2083000,
    2414000,
    4950000,
  };
  display_menu("Toyota",toyota_car_names,toyota_car_prices,9);
  std::cout << "Input Number According to the type of Car: ";
  int Cars;
  std::cin >> Cars;
  std::cout << "You selected "
            << toyota_car_names[Cars-1]
            << " for "
            << toyota_car_prices[Cars-1]
            << " yen\n";
  std::cout << "To be Comformed Type y Yes, if type n if No: ";
  char Yes_or_No;
  std::cin >> Yes_or_No;
  if (Yes_or_No == 'y' ) {
    std::cout << "You Ordered "
              << toyota_car_names[Cars-1]
              << std::endl;
  }
  else if (Yes_or_No == 'n') {
    std::cout << "You Canceled the order.\n";
  }
}

@PP Namias

A small heads up. Where yo have lines like this in your code, you should be using a '==' instead of '=', as your assigning Yes_or_No with a 'y' in the first line, instead of checking for equality of values.

Same goes for line 237. Use double equals, NOT a single equal.

Lastly, place the break command AFTER the right parenthesis of the cases.

Hope this helps.

1
2
3
4
5
6
7
if (Yes_or_No = 'y') {
   			cout << "You Ordered Honda Odyssey";
		   }
   		else if (Yes_or_No = 'n') {
   			cout << "You Canceled the order.";
   			break;
}
Consider:

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
#include <iostream>
#include <string>
#include <iterator>

struct Cars {
	std::string name;
	int price {};
};

void display_menu(const std::string& manufacturer, const Cars cars[], size_t numCars)
{
	std::cout << manufacturer << " Cars\n";

	for (size_t i = 0; i < numCars; ++i)
		std::cout << i + 1 << ". " << cars[i].name << " for " << cars[i].price << " yen\n";
}

int main()
{
	const Cars carNames[] {
		{"Camry", 2042000},
		{"Corolla Altis", 1595000},
		{"Vios", 1056000},
		{"Wigo", 70000},
		{"Yaris", 1065000},
		{"Corolla Cross", 1650000},
		{"FJ Cruiser", 2083000},
		{"Fortuner", 2414000},
		{"Land Cruiser", 4950000}
	};

	display_menu("Toyota", carNames, std::size(carNames));

	int Cars {};

	while (((std::cout << "Input Number According to the type of Car: ") && !(std::cin >> Cars)) || (Cars < 1 || Cars > std::size(carNames))) {
		std::cout << "Invalid number entered\n";
		std::cin.clear();
		std::cin.ignore(1000, '\n');
	}

	std::cout << "You selected " << carNames[Cars - 1].name << " for " << carNames[Cars - 1].price << " yen\n";

	char YesNo {};

	do {
		std::cout << "To be Confirmed Type y for Yes, if not type n if No: ";
		std::cin >> YesNo;
		std::cin.ignore(1000, '\n');

		if (YesNo == 'y')
			std::cout << "You Ordered " << carNames[Cars - 1].name << '\n';
		else
			if (YesNo == 'n')
				std::cout << "You Cancelled the order.\n";
			else
				std::cout << "Unknown input. Please enter again\n";
	} while (YesNo != 'y' && YesNo != 'n');
}

Topic archived. No new replies allowed.