fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct IceCream {
  6. string name;
  7. int price;
  8. int amount;};
  9.  
  10. int main() {
  11. int m, n;
  12. cin >> m >> n;
  13.  
  14. IceCream menu[100];
  15. int Items = 0;
  16.  
  17. for (int i = 0; i < m; i++) {
  18. string name;
  19. int price, amount;
  20. cin >> name >> price >> amount;
  21.  
  22. if (amount < 0) {
  23. cout << "Item Quantity should be a non-negative integer!" << endl;
  24. i--; continue;}
  25.  
  26. menu[Items].name = name;
  27. menu[Items].price = price;
  28. menu[Items].amount = amount;
  29. Items++;}
  30. if (Items == 0) {
  31. cout << "Not enough ice-creams in the stock!" << endl;
  32. return 0;}
  33. int minimumPrice = menu[0].price;
  34. int cheapestIndex = 0;
  35. for (int i = 1; i < Items; i++) {
  36. if (menu[i].price < minimumPrice) {
  37. minimumPrice = menu[i].price;
  38. cheapestIndex = i;}}
  39. if (menu[cheapestIndex].amount >= n) {
  40. cout << menu[cheapestIndex].name << " x " << n << endl;
  41. cout << "Total: " << menu[cheapestIndex].price * n << " Toman" << endl;
  42. } else {cout << "Not enough ice-creams in the stock!" << endl;}
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0.01s 5280KB
stdin
3 5
Chocolate
15000
-2
Vanilla
12000
4
Strawberry
18000
3
stdout
Item Quantity should be a non-negative integer!
Not enough ice-creams in the stock!