Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.42 KB | None | 0 0
  1. //Rextester.Program.Main is the entry point for your code. Don't change it.
  2. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8.  
  9. namespace Rextester
  10. {
  11.     public class Program
  12.     {
  13.         public static void Main(string[] args)
  14.         {
  15.             bool notAgain = true;
  16.             while(notAgain){
  17.                 List<int> iList = new List<int>();
  18.                 while(true){
  19.                     String input = Console.ReadLine();
  20.                     int selectedOption;
  21.                     if(int.TryParse(input, out selectedOption)){
  22.                         iList.Add(selectedOption);    
  23.                     }
  24.                     else
  25.                     {
  26.                         if(input != "again"){
  27.                             notAgain = false;
  28.                             displayResults(iList);
  29.                             break;
  30.                         }else {
  31.                             displayResults(iList);
  32.                             break;
  33.                         }
  34.                     }
  35.            }
  36.         }
  37.     }
  38.        
  39.         public static void displayResults(List<int> iList){
  40.             Console.WriteLine(divisibleBy6AndInRange15120(iList));
  41.             Console.WriteLine(inRagne2187(iList));
  42.             Console.WriteLine(sumDifference(iList));
  43.         }
  44.        
  45.         public static int divisibleBy6AndInRange15120(List<int> iList){
  46.             int counter = 0;
  47.             foreach(int element in iList){
  48.                 if((element % 6 == 0) && element >= 15 && element <= 120){
  49.                     counter++;
  50.                 }
  51.             }
  52.             return counter;
  53.         }
  54.        
  55.         public static int inRagne2187(List<int> iList){
  56.             int counter = 0;
  57.              foreach(int element in iList){
  58.                 if(element >= 21 && element <= 87){
  59.                     counter++;
  60.                 }
  61.             }
  62.             return counter;
  63.         }
  64.        
  65.         public static int sumDifference(List<int> iList){
  66.             int sum = 0;
  67.               foreach(int element in iList){
  68.                 if(element % 2 == 0){
  69.                     sum -= element;
  70.                 }else{
  71.                     sum += element;
  72.                 }
  73.             }
  74.             return sum;
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement