0

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.

27th Aug 2017, 7:27 AM
gorgamin
gorgamin - avatar
2 ответов
+ 3
Using this tool: http://asciitohex.com Copy each to post to the ASCII panel, click [Convert], copy the HEX output into separate files, then: $ md5sum topPost.txt bottomPost.txt 36fb44400057bcdebc15a502f8089979 topPost.txt 36fb44400057bcdebc15a502f8089979 bottomPost.txt Since the hashes are the same, these two posted codes appear to be identical (i.e., are probably. There remains a remote chance of hash collision). I didn't check to see if you had CodePlayground codes (edit: you don't). You may have things that will show up as HTML entities in your first code using the linked site.
26th Aug 2017, 10:13 PM
Kirk Schafer
Kirk Schafer - avatar
0
(There's not enough space. This is the second code.) #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; }
26th Aug 2017, 7:23 PM
gorgamin
gorgamin - avatar