Arxero

Untitled

Oct 4th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2.  
  3. class PriceChangeAlert
  4. {
  5.     static void Main()
  6.     {
  7.         int n = int.Parse(Console.ReadLine());
  8.  
  9.  
  10.  
  11.         double granica = double. Parse(Console.ReadLine());
  12.  
  13.  
  14.         double last = double.Parse(Console.ReadLine());
  15.  
  16.         for (int i = 0; i < n - 1; i++) {
  17.             double c = double.Parse(Console.ReadLine());
  18.             double div = Proc(last, c); bool isSignificantDifference = imaliDif(div, granica);
  19.  
  20.  
  21.  
  22.             string message = Get(c, last, div, isSignificantDifference);
  23.             Console.WriteLine(message);
  24.  
  25.             last = c; }             }
  26.  
  27.     private static string Get(double c, double last, double razlika, bool etherTrueOrFalse)
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.     {   string to = "";
  35.         if (razlika == 0)
  36.                                                             {
  37.                                                                 to = string.Format("NO CHANGE: {0}", c);
  38.                                                             }
  39.         else if (!etherTrueOrFalse){
  40.             to = string.Format("MINOR CHANGE: {0} to {1} ({2:F2}%)", last, c, razlika);}
  41.         else if (etherTrueOrFalse && (razlika > 0))
  42. {
  43. to = string.Format("PRICE UP: {0} to {1} ({2:F2}%)", last, c, razlika);
  44. }
  45.         else if (etherTrueOrFalse && (razlika < 0))
  46. to = string.Format("PRICE DOWN: {0} to {1} ({2:F2}%)", last, c, razlika);
  47.         return to;}
  48.         private static bool imaliDif(double granica, double isDiff)
  49.         {
  50.         if (Math.Abs(granica) >= isDiff)
  51.         {
  52.         return true;
  53.         }
  54.         return false;
  55.         }
  56.  
  57. private static double Proc(double l, double c)
  58. {
  59. double r = (c - l) / l;
  60. return r;
  61. }
  62. }
Add Comment
Please, Sign In to add comment