Advertisement
Spocoman

Food for Pets

Sep 19th, 2023 (edited)
972
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int days, dailyDogFood, dailyCatFood, eatenDogsFood = 0, eatenCatsFood = 0;
  8.     cin >> days;
  9.  
  10.     double availableFood, cookies = 0;
  11.     cin >> availableFood;
  12.  
  13.     for (int i = 1; i <= days; i++) {
  14.         cin >> dailyDogFood >> dailyCatFood;
  15.  
  16.         if (i % 3 == 0) {
  17.             cookies += 0.1 * (dailyDogFood + dailyCatFood);
  18.         }
  19.         eatenDogsFood += dailyDogFood;
  20.         eatenCatsFood += dailyCatFood;
  21.     }
  22.  
  23.     double totalEatenFood = eatenDogsFood + eatenCatsFood;
  24.  
  25.     printf("Total eaten biscuits: %igr.\n", (int)round(cookies));
  26.     printf("%.2f%% of the food has been eaten.\n", 100.0 * totalEatenFood / availableFood);
  27.     printf("%.2f%% eaten from the dog.\n", 100.0 * eatenDogsFood / totalEatenFood);
  28.     printf("%.2f%% eaten from the cat.\n", 100.0 * eatenCatsFood / totalEatenFood);
  29.  
  30.     return 0;
  31. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement