Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Rextester.Program.Main is the entry point for your code. Don't change it.
- //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Rextester
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- bool notAgain = true;
- while(notAgain){
- List<int> iList = new List<int>();
- while(true){
- String input = Console.ReadLine();
- int selectedOption;
- if(int.TryParse(input, out selectedOption)){
- iList.Add(selectedOption);
- }
- else
- {
- if(input != "again"){
- notAgain = false;
- displayResults(iList);
- break;
- }else {
- displayResults(iList);
- break;
- }
- }
- }
- }
- }
- public static void displayResults(List<int> iList){
- Console.WriteLine(divisibleBy6AndInRange15120(iList));
- Console.WriteLine(inRagne2187(iList));
- Console.WriteLine(sumDifference(iList));
- }
- public static int divisibleBy6AndInRange15120(List<int> iList){
- int counter = 0;
- foreach(int element in iList){
- if((element % 6 == 0) && element >= 15 && element <= 120){
- counter++;
- }
- }
- return counter;
- }
- public static int inRagne2187(List<int> iList){
- int counter = 0;
- foreach(int element in iList){
- if(element >= 21 && element <= 87){
- counter++;
- }
- }
- return counter;
- }
- public static int sumDifference(List<int> iList){
- int sum = 0;
- foreach(int element in iList){
- if(element % 2 == 0){
- sum -= element;
- }else{
- sum += element;
- }
- }
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement