Array Question

I'm having a little trouble figuring something out. Below is the code for a function in program I am writing for a class. The purpose of this section is to select vehicle options. The problem I am trying to workout is located at the ** below. It is supposed to check the optionsflag array to see it has already been selected (later on in the code, after being selected, the optionsflag array is changed from 1, not selected, to 0, selected). But it is not running that part and the code is letting me chose the same option multiple times. I've included a for loop displaying the contents of the optionsflag array so you can see that it is in fact changing the flag is changing from 1 to 0. Thanks for the help.

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
double vehicleoptionsmenu(int modeloption)
{
	string optionslist[5] = { "Moonroof", "Heated mirrors/rear glass", "Automatic transmission", "4.7 liter V8 engine", "Heated leather seats" };
	double optionsprice[5] = { 1000.00, 357.00, 850.00, 1250.00, 350.00 };
	double optionstotalprice = 0.0;
	int optionsflag[5] = { 1, 1, 1, 1, 1 };
	int ctr, optionselect;
	cout << "Select the vehicle options or select 0 to continue:" << endl;
	for (ctr = 0; ctr < 5; ctr++)
	{
		cout << ctr + 1 << ") " << optionsflag[ctr] << endl;
	}
	for (ctr = 0; ctr < 5; ctr++)
	{
		cout << ctr + 1 << ") " << optionslist[ctr] << endl;
	}
	cin >> optionselect;
	**if (optionsflag[optionselect - 1] == 0)
	{
		cout << "That option has already been selected" << endl;
	}
	while (optionselect != 0)
	{
		optionstotalprice = optionstotalprice + optionsprice[optionselect-1];
		if (modeloption == 4 && optionselect == 4)
		{
			optionstotalprice = optionstotalprice - 1250.00;
			cout << "The Coronet includes the V8 in the standard package" << endl;
		}
		if (optionselect != 0)
		{
			optionsflag[optionselect-1] = 0;
		}
		//cout << optionstotalprice;
		cout << "Select the vehicle options or select 0 to continue:" << endl;
		for (ctr = 0; ctr < 5; ctr++)
		{
			cout << ctr + 1 << ") " << optionsflag[ctr] << endl;
		}
		for (ctr = 0; ctr < 5; ctr++)
		{
			cout << ctr + 1 << ") " << optionslist[ctr] << endl;
		}
		cin >> optionselect;
	}
	return optionstotalprice;
}
Your condition is outside the loop, so it will be only checked after first input, where no flags could possibly be set to 0.
Topic archived. No new replies allowed.