Hey guys, seeing as I've only been programming in C++ for a few weeks, I've looked around the forum and seen a brilliant thread with some beginner exercises. I've made a simple vending machine program that asks the user to key in an option of 1-5 for what drink they would like. Once the user has keyed in an option, they are then shown what option they have made. I made it using IF statements, and it worked perfectly. However, I'm having some trouble making the same program but with SWITCH statements. Can you guys have a look and tell me where I'm going wrong? (I'm using Anjuta IDE on Ubuntu 12.04 if you needed to know!)
Remove the ' ' from the nums. With those there, they are chars, not ints.
On another note:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
cout << "You have chosen Coca Cola "; break;
cout << "You have chosen Diet Coke "; break;
cout << "You have chosen Sprite "; break;
cout << "You have chosen Fanta Orange "; break;
cout << "You have chosen water "; break;
Would probably be a better approach to indentation. Imagine you have 20 cases instead of just 5.
Edit: Or you can change the type of beverage to char instead of int.