Advertisement
ralichka

Nested.Loop.Exercises-08.Fishing

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