petaryankov00

Food for Pets

May 1st, 2020
1,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LoopsExamTasks
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int days = int.Parse(Console.ReadLine());
  10.             double foodCount = double.Parse(Console.ReadLine());
  11.  
  12.             double biscuits = 0;
  13.             double eatenFoodDog = 0;
  14.             double eatenFoodCat = 0;
  15.  
  16.             for (int i = 1; i <= days; i++)
  17.             {
  18.                 double foodDog = double.Parse(Console.ReadLine());
  19.                 double foodCat = double.Parse(Console.ReadLine());
  20.  
  21.                 eatenFoodDog += foodDog;
  22.                 eatenFoodCat += foodCat;
  23.                
  24.  
  25.                 if (i % 3 == 0)
  26.                 {
  27.                     biscuits = (foodDog + foodCat) * 0.1;
  28.                 }
  29.  
  30.             }
  31.             double allEatenFood = eatenFoodDog + eatenFoodCat;
  32.             double percentFood = (allEatenFood / foodCount) * 100;
  33.             double percentDog = (eatenFoodDog / allEatenFood) * 100;
  34.             double percentCat = (eatenFoodCat / allEatenFood) * 100;
  35.  
  36.             Console.WriteLine($"Total eaten biscuits: {Math.Round(biscuits)}gr.");
  37.             Console.WriteLine($"{percentFood:F2}% of the food has been eaten.");
  38.             Console.WriteLine($"{percentDog:F2}% eaten from the dog.");
  39.             Console.WriteLine($"{percentCat:F2}% eaten from the cat.");
  40.  
  41.            
  42.  
  43.            
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment