fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. // 1: coke (35)
  7. // 2: black tea (30)
  8. // 3: milk tea (40)
  9.  
  10. int choice;
  11. cin >> choice;
  12.  
  13. int price;
  14. switch (choice) {
  15. case 1:
  16. price = 35;
  17. break;
  18. case 2:
  19. price = 30;
  20. break;
  21. case 3:
  22. price = 40;
  23. break;
  24. default:
  25. cout << "Not an option. Bye." << endl;
  26. return -1; // abnormal exit
  27. }
  28.  
  29. int coins;
  30. cin >> coins;
  31.  
  32. if (coins >= price) {
  33. cout << "You got your beverage with changes "
  34. << (coins - price) << " TWD" << endl;
  35. } else {
  36. cout << "Not enough coins. Insert more." << endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5476KB
stdin
3 50
stdout
You got your beverage with changes 10 TWD