Terminating an option for a variable

Im trying to make my program so that after the user chooses an item to purchase they aren't able to choose it again. I tried using bool to make this work but when I run the code I am still able to choose the first item over and over again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
case 1:
{
if (bool item1 = false)
cout << "Item is no longer available!" << endl;
else if (currency >= price1)
{
cout << "Thank You!" << endl;
cout << "*You purchased the beanie for $10.*" << endl << endl;
item1 = "Not Available";
currency = currency - price1;
available--;
bool item1 = false;
}
else
cout << "Sorry, you do not have enough currency to purchase this item." << endl;

break;
}
Line 3: You're using the assignment operator (=), not the equality operator (==). This statement will never be true.

Line 3: item1 goes out of scope at line 18, therefore it's value is not maintained across executions of the switch statement.

Line 12: What is this line supposed to do? It immediately goes out of scope at line 13.



Line 12 I was trying to set the variable to false so that when this loop runs again and the user chooses item 1 again the first if statement will run and not let them purchase it again
Line 12 does not accomplish that. It declares a new variable (with the same name) that immediately goes out of scope.
Topic archived. No new replies allowed.