alexbancheva

Fishing_Nested_Loops_Exercise {

Dec 2nd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Fishing_Nested_Loops_Exercise
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int dayQuota = int.Parse(Console.ReadLine());
  10.             string nameFish = string.Empty;
  11.             int counterFish = 0;
  12.            
  13.             double profit = 0;
  14.             double price = 0; // ?? = 0.00;
  15.  
  16.             while (nameFish != "Stop")
  17.             {
  18.  
  19.                 for (int i = 1; i <= dayQuota; i++)
  20.                 {
  21.                     nameFish = Console.ReadLine();
  22.  
  23.                     if (nameFish == "Stop")
  24.                     {
  25.                         break;
  26.                     }
  27.  
  28.                     double kgFish = double.Parse(Console.ReadLine());
  29.  
  30.                     for (int j = 0; j < nameFish.Length; j++)
  31.                     {
  32.                         price += nameFish[j];
  33.                     }
  34.                     price = price / kgFish;
  35.  
  36.                         if (i % 3 == 0)
  37.                         {
  38.                             profit += price;
  39.                         }
  40.                         else
  41.                         {
  42.                             profit -= price;
  43.                         }
  44.                         counterFish++;
  45.                         price = 0;
  46.                 }
  47.  
  48.                 if (counterFish == dayQuota)
  49.                 {
  50.                         Console.WriteLine("Lyubo fulfilled the quota!");
  51.                         break;
  52.                 }      
  53.             }
  54.  
  55.             if (profit >= 0)
  56.             {
  57.                 Console.WriteLine($"Lyubo's profit from {counterFish} fishes is {profit:f2} leva.");
  58.             }
  59.             else
  60.             {
  61.                 Console.WriteLine($"Lyubo lost {Math.Abs(profit):f2} leva today.");
  62.             }
  63.         }
  64.     }
  65. }
Add Comment
Please, Sign In to add comment