Advertisement
Guest User

MonthlyPours

a guest
Jan 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace RainPours
  8. {
  9.     class Program
  10.     {
  11.         public static void MonthlyPours(int[] StationArray, Random randomGenVal)
  12.         {          
  13.             for (int i=1;i<StationArray.Length;i++)
  14.             {              
  15.                 StationArray[i] = randomGenVal.Next(0,31);
  16.             }
  17.         }
  18.  
  19.         public static int MaxValMonth(int[] StationArray)
  20.         {
  21.             int MaxValArr = StationArray[0];
  22.             int highestValDay = 0;
  23.             for(int i=1;i<StationArray.Length;i++)
  24.             {
  25.                 if(StationArray[i]>MaxValArr)
  26.                 {
  27.                     MaxValArr = StationArray[i];
  28.                     highestValDay = i;
  29.                 }
  30.             }
  31.             Console.WriteLine("The greatest value for this month is: {0} and the day it is on is {1}", MaxValArr, highestValDay);
  32.             return MaxValArr;          
  33.         }
  34.  
  35.         public static void AvgMontly(int[] StationArray)
  36.         {
  37.             int Sum = StationArray[0];
  38.             for (int i = 1; i < StationArray.Length; i++)
  39.             {
  40.                 Sum += StationArray[i];
  41.             }
  42.             int Average = Sum / StationArray.Length;
  43.  
  44.             Console.WriteLine("The average is: {0}",Average);  
  45.         }
  46.  
  47.         public static void HigherThanAvgMonthly(int[] StationArray)
  48.         {
  49.             Console.Write("On these days the rain was higher than average: ");
  50.             for (int i = 1; i < StationArray.Length; i++)
  51.             {              
  52.                 if (StationArray[i] > StationArray.Average())
  53.                 {
  54.                     Console.Write(" {0} ", i);
  55.                 }
  56.             }
  57.             Console.WriteLine();
  58.         }
  59.  
  60.         public static void NoRainDays(int[] StationArray)
  61.         {
  62.             Console.Write("On these days there was no rain: ");
  63.             for (int i=1;i<StationArray.Length;i++)
  64.             {
  65.                 if(StationArray[i]==0)
  66.                 {
  67.                     Console.Write(" {0} ",i);
  68.                 }
  69.             }
  70.             Console.WriteLine();
  71.         }
  72.  
  73.         public static void FindHighestValOfEach(int MaxValM1, int MaxValM2, int MaxValM3)
  74.         {
  75.             int top2Month = 0;
  76.             int monthNo = 0;
  77.             if(MaxValM1>MaxValM2)
  78.             {
  79.                 top2Month = MaxValM1;
  80.                 monthNo = 1;
  81.             }
  82.             else
  83.             {
  84.                 top2Month = MaxValM2;
  85.                 monthNo = 2;
  86.             }
  87.             if (MaxValM3>top2Month)
  88.             {
  89.                 top2Month = MaxValM3;
  90.                 monthNo = 3;
  91.             }
  92.             Console.WriteLine("The greatest value amongst all is on month number: {0} and is {1}",monthNo,top2Month);
  93.         }
  94.  
  95.         public static void TimesMaxMonthHappened(int[] StationArray,int MaxValMonth)
  96.         {
  97.             int repetitions = 0;
  98.             for(int i=1;i<StationArray.Length;i++)
  99.             {
  100.                 if(StationArray[i]==MaxValMonth)
  101.                 {
  102.                     repetitions++;
  103.                 }
  104.             }
  105.             Console.WriteLine("Times the max val of this month has repeated: {0}",repetitions);
  106.         }
  107.  
  108.         static void Main(string[] args)
  109.         {
  110.             Random randomGenVal = new Random();
  111.             int[] StationOne = new int[32];
  112.             MonthlyPours(StationOne, randomGenVal);
  113.             int[] StationTwo = new int[32];
  114.             MonthlyPours(StationTwo, randomGenVal);
  115.             int[] StationThree = new int[32];
  116.             MonthlyPours(StationThree, randomGenVal);
  117.  
  118.             /*
  119.             MaxValMonth(StationOne);
  120.             MaxValMonth(StationTwo);
  121.             MaxValMonth(StationThree);
  122.             */
  123.  
  124.             Console.WriteLine();
  125.  
  126.             FindHighestValOfEach(MaxValMonth(StationOne), MaxValMonth(StationTwo), MaxValMonth(StationThree));
  127.  
  128.             Console.WriteLine();
  129.  
  130.             AvgMontly(StationOne);
  131.             AvgMontly(StationTwo);
  132.             AvgMontly(StationThree);
  133.  
  134.             Console.WriteLine();
  135.  
  136.             NoRainDays(StationOne);
  137.             NoRainDays(StationTwo);
  138.             NoRainDays(StationThree);
  139.  
  140.             Console.WriteLine();
  141.  
  142.             HigherThanAvgMonthly(StationOne);
  143.             HigherThanAvgMonthly(StationTwo);
  144.             HigherThanAvgMonthly(StationThree);
  145.  
  146.             Console.WriteLine();
  147.  
  148.             TimesMaxMonthHappened(StationOne,MaxValMonth(StationOne));
  149.             TimesMaxMonthHappened(StationTwo, MaxValMonth(StationTwo));
  150.             TimesMaxMonthHappened(StationThree, MaxValMonth(StationThree));
  151.         }
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement