how to change this to if...else statement c++

closed account (3p4G8vqX)
cashRegister counter;
dispenserType candy(500, 50);
dispenserType chips(100, 65);
dispenserType gum(75, 45);
dispenserType cookies(100, 85);
int choice;

while (choice != 9)
{
switch (choice)
{
case 1:
sellProduct(candy, counter);
break;
case 2:
sellProduct(chips, counter);
break;
case 3:
sellProduct(gum, counter);
break;
case 4:
sellProduct(cookies, counter);
break;
default:
cout << "Invalid selection." << endl;
}//end switch
Last edited on
Replace:
1
2
3
4
5
switch (choice)
.
.
.
}//end switch 


To:
1
2
3
4
5
6
7
8
9
10
if (choice == 1)
	sellProduct(candy, counter);
else if (choice == 2)
	sellProduct(chips, counter);
else if (choice == 3)
	sellProduct(gum, counter);
else if (choice == 4)
	sellProduct(cookies, counter);
else
	cout << "Invalid selection." << endl;


Hope this help
closed account (3p4G8vqX)
thnx
Topic archived. No new replies allowed.