Advertisement
vencinachev

Exam04

Nov 28th, 2021
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int food = int.Parse(Console.ReadLine());
  10.             int days = int.Parse(Console.ReadLine());
  11.             food *= 1000; // grams
  12.             for (int i = 0; i < days; i++)
  13.             {
  14.                 int grams = int.Parse(Console.ReadLine());
  15.                 food -= grams;
  16.             }
  17.             if (food >= 0)
  18.             {
  19.                 Console.WriteLine($"Food is enough! Leftovers: {food} grams.");
  20.             }
  21.             else
  22.             {
  23.                 Console.WriteLine($"Food is not enough. You need {-food} grams more.");
  24.             }
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement