desislava_topuzakova

04. Food for pets

Feb 19th, 2022
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. //входни данни
  8. int days;
  9. cin >> days;
  10.  
  11. double totalFood;
  12. cin >> totalFood;
  13.  
  14. double totalBiscuits = 0; //общо гр изядени бисквити за всички дни
  15. double totalEatenFoodForAllDays = 0;// общо изядени гр от двете за всички дни
  16. double totalEatenDog = 0; //общо изядени гр от кучето за всички дни
  17. double totalEatenCat = 0; // общо изядени гр от котката за всички дни
  18.  
  19. //за всеки ден от 1 до последния -> изядено кол от кучето и изядено кол от котката
  20. for (int day = 1; day <= days; day++)
  21. {
  22. int eatenDog, eatenCat;
  23. cin >> eatenDog; //изядено от кучето
  24. totalEatenDog += eatenDog;
  25. cin >> eatenCat; //изядено от котката
  26. totalEatenCat += eatenCat;
  27.  
  28. int totalEatenForDay = eatenDog + eatenCat; //общо за деня
  29. totalEatenFoodForAllDays += totalEatenForDay;
  30.  
  31. //бисквити
  32. if (day % 3 == 0)
  33. {
  34. double biscuits = 0.10 * totalEatenForDay;
  35. totalBiscuits += biscuits;
  36. }
  37.  
  38. }
  39.  
  40. //отпечатвам статистиката
  41. cout << "Total eaten biscuits: " << round(totalBiscuits) << "gr." << endl;
  42.  
  43. cout.setf(ios::fixed);
  44. cout.precision(2);
  45.  
  46. cout << totalEatenFoodForAllDays / totalFood * 100 << "% of the food has been eaten." << endl;
  47. cout << totalEatenDog / totalEatenFoodForAllDays * 100 << "% eaten from the dog." << endl;
  48. cout << totalEatenCat / totalEatenFoodForAllDays * 100 << "% eaten from the cat." << endl;
  49. return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment