C++ Can you Spot the Difference?
The first code keeps telling me I can't choose option 1,but the second code works perfectly.It's the same code,so why isn't the first one working?The first code is my own that I typed into CodeBlocks.The second code I copied and pasted from a website. #include <iostream> #include <iomanip> using namespace std; int main() { int number; float cost; char beverage; bool validBeverage; cout << fixed << showpoint << setprecision(2); do { cout << "Hot Beverage Menu" << endl << endl; cout << "1: Coffee R15.00" << endl; cout << "2: Tea R12.50" << endl; cout << "3: Hot Chocolate R17.00" << endl; cout << "4: Cappuccino R22.50" << endl <<endl << endl; cout << "Please enter the choice of drink" << endl; cout << " (a number from 1 to 4, or 0 to quit):" << endl << endl; cin >> beverage; switch(beverage) { case '1': case '2': case '3': case '4': validBeverage = true; break; default: validBeverage = false; } if (validBeverage == true) { cout << "How many cups would you like?" << endl; cin >> number; } switch (beverage) { case '1': cost = number * 15.00; cout << "The total cost is R" << cost << endl; break; case '2': cost = number * 12.50; cout << "The total cost is R" << cost << endl; break; case '3': cost = number * 17.00; cout << "The total cost is R" << cost << endl; break; case '4': cost = number * 22.50; cout << "The total cost is R" << cost << endl; break; case '0': cout << "Please come again." << endl; break; default: cout << "Invalid selection."; cout << " Try again please." << endl; } } while (beverage != '0'); return 0; } __ See below for second code.