Dianov

Data Types and Variables - Exercise (07. Water Overflow)

Aug 7th, 2021
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace WaterOverflow
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int tankCapacity = 255;
  10.             int pourTimes = int.Parse(Console.ReadLine());
  11.             int sum = 0;
  12.  
  13.             for (int i = 0; i < pourTimes; i++)
  14.             {
  15.                 int pouredLiters = int.Parse(Console.ReadLine());
  16.                 sum += pouredLiters;
  17.                 if (sum > tankCapacity)
  18.                 {
  19.                     Console.WriteLine("Insufficient capacity!");
  20.                     sum -= pouredLiters;
  21.                 }
  22.             }
  23.             Console.WriteLine(sum);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment