fbinnzhivko

Untitled

May 13th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int years = int.Parse(Console.ReadLine());
  7.         decimal washingMachine = decimal.Parse(Console.ReadLine());
  8.         int toy = int.Parse(Console.ReadLine());
  9.  
  10.         int evenCounter = 0;
  11.         int oddCounter = 0;
  12.         int moneyForBirthday = 10/2;
  13.  
  14.         decimal total = 0;
  15.  
  16.         for (decimal i = 0; i < years; i++)
  17.         {
  18.             oddCounter = years / 2;
  19.             if (years % 2 != 0) { oddCounter++; }
  20.  
  21.             evenCounter = years / 2;
  22.         }
  23.  
  24.         int sborNaChislata = 0, j;
  25.         for (j = 0; j <= years; j = j + 2)
  26.         {
  27.             sborNaChislata += j;
  28.         }
  29.         total = sborNaChislata * moneyForBirthday;   /* sborNaChislata = sum of all odd number */
  30.  
  31.         decimal totalPlus = oddCounter * toy;
  32.  
  33.         decimal savedMoney = total + totalPlus - evenCounter;
  34.        
  35.         if (savedMoney >= washingMachine)
  36.         {
  37.             Console.WriteLine("Yes! {0:f2}", savedMoney - washingMachine);
  38.         }
  39.         else
  40.         {
  41.             Console.WriteLine("No! {0:f2}", Math.Abs(washingMachine - savedMoney));
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment