Advertisement
MartisK

C++ uždavinys. Pirkiniai

Dec 7th, 2020 (edited)
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int CountProductsAveragePrice(int prices[], int count)
  4. {
  5.     int total = 0;
  6.     for (int i = 0; i < count; i++)
  7.     {
  8.         total += prices[i];
  9.     }
  10.     return total / count;
  11. }
  12.  
  13. double CountProductsTotalWeight(int weights[], int count)
  14. {
  15.     double total = 0;
  16.     for (int i = 0; i < count; i++)
  17.     {
  18.         total += weights[i];
  19.     }
  20.     return total / 1000;
  21. }
  22.  
  23. int main()
  24. {
  25.     int productsCount = 3, canCarry = 2;
  26.  
  27.     int productPrice[productsCount], productWeight[productsCount];
  28.  
  29.     productPrice[0] = 10, productWeight[0] = 700;
  30.     productPrice[1] = 10, productWeight[1] = 700;
  31.     productPrice[2] = 10, productWeight[2] = 700;
  32.  
  33.     double totalWeight = CountProductsTotalWeight(productWeight, productsCount);
  34.  
  35.     std::cout << "Vidutinė prekių kaina centais yra " << CountProductsAveragePrice(productPrice, productsCount) << std::endl;
  36.     if (totalWeight > canCarry)
  37.     {
  38.         std::cout << "Saulius visų pirkinių parnešti negalės.";
  39.     }
  40.     else
  41.     {
  42.         std::cout << "Saulius galės parnešti visus pirkinius.";
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement