Advertisement
NelIfandieva

SimpleArithmeticCalculationsThreeArguments_Wrong

Mar 7th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Globalization;
  6. using System.Text.RegularExpressions;
  7.  
  8. namespace Problem01_PadawanEquipment
  9. {
  10.     class MainClass
  11.     {
  12.         /* */
  13.  
  14.         public static void Main()
  15.         {
  16.             char[] sep = { ' ' };
  17.             var input = Console.ReadLine()
  18.                                .Split(sep, StringSplitOptions.RemoveEmptyEntries)
  19.                                .ToList();
  20.             List<double> numsFromInput = ExtractDoublesFromInput(input);
  21.             bool addition = false;
  22.             bool additionThenSubtraction = false;
  23.             bool subtractionThenAddition = false;
  24.             bool subtraction = false;
  25.             double result = 0;
  26.             for (int i = 0; i < input.Count; i++)
  27.             {
  28.                 if(input[1] == "+"&& input[3] == "+")
  29.                 {
  30.                     addition = true;
  31.                 }
  32.                 else if(input[1] == "+" && input[3] == "-")
  33.                 {
  34.                     additionThenSubtraction = true;
  35.                 }
  36.                 else if(input[1] == "-" && input[3] == "+")
  37.                 {
  38.                     subtractionThenAddition = true;
  39.                 }
  40.                 else
  41.                 {
  42.                     subtraction = true;
  43.                 }
  44.             }
  45.             if(addition)
  46.             {
  47.                 result = numsFromInput[0] + numsFromInput[1] + numsFromInput[2];
  48.                 Console.Write(result);
  49.             }
  50.             else if(additionThenSubtraction)
  51.             {
  52.                 result = numsFromInput[0] + numsFromInput[1] - numsFromInput[2];
  53.                 Console.Write(result);
  54.             }
  55.             else if(subtractionThenAddition)
  56.             {
  57.                 result = numsFromInput[0] - numsFromInput[1] + numsFromInput[2];
  58.                 Console.Write(result);
  59.             }
  60.             else if(subtraction)
  61.             {
  62.                 result = numsFromInput[0] - numsFromInput[1] - numsFromInput[2];
  63.                 Console.Write(result);
  64.             }
  65.             else
  66.             {
  67.                 Console.Write("Please enter numbers and the '+' or '-' signs.");
  68.             }
  69.         }
  70.         public static List<double> ExtractDoublesFromInput(List<string> input)
  71.         {
  72.             List<double> doublesFromInput = new List<double>();
  73.             doublesFromInput[0] = double.Parse(input[0].ToString());
  74.             doublesFromInput[1] = double.Parse(input[2].ToString());
  75.             doublesFromInput[2] = double.Parse(input[4].ToString());
  76.             return doublesFromInput;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement