fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. float coffee = 3.50;
  6. float tea = 2.75;
  7. float smoothie = 5.00;
  8. double totalCost = 0.0;
  9. float total;
  10. float choice;
  11.  
  12. cin >> total;
  13. cout << "How many drink do u want to order: " << total << endl;
  14.  
  15.  
  16.  
  17. for ( int i = 0; i <= total; i++)
  18. {
  19. cin >> choice;
  20. cout << "Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): " << endl;
  21. if (choice == 1)
  22. totalCost = totalCost + coffee; // add coffee price
  23. else if (choice == 2)
  24. totalCost = totalCost + tea; // add tea price
  25. else if (choice == 3)
  26. totalCost = totalCost + smoothie; // add smoothie price
  27. else
  28. cout << "Invalid choice. Try again.\n";
  29.  
  30. }
  31. cout << "Total cost: $" << totalCost << endl;
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5316KB
stdin
31
stdout
How many drink do u want to order: 31
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Select a choice (1 = Coffee, 2 = Tea, 3 = Smoothie): 
Invalid choice. Try again.
Total cost: $0