TeHArGiS10

Untitled

Jul 22nd, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 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 Tutorials
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int numAmount = 0;
  14. int numCount = 0;
  15. int equationCount = 0;
  16. double firstValue = 0.0;
  17. double nextValue = 0.0;
  18. string equationMark;
  19.  
  20. Start:
  21. numAmount = 0;
  22. numCount = 0;
  23. equationCount = 0;
  24. Console.Write("Write the amount of numbers: ");
  25.  
  26. try
  27. {
  28. numAmount = Convert.ToInt32(Console.ReadLine());
  29. }
  30.  
  31. catch (FormatException)
  32. {
  33. Console.WriteLine("ERROR: Number required");
  34. Console.WriteLine();
  35. goto Start;
  36. }
  37. Console.WriteLine();
  38.  
  39. List < double > numStore = new List<double>();
  40.  
  41. for (int i = 0; i < numAmount; i++)
  42. {
  43. numCount++;
  44. Console.Write("Number " + numCount + ": ");
  45.  
  46. if(i%2 == 0)
  47. {
  48. try
  49. {
  50. nextValue = Convert.ToDouble(Console.ReadLine());
  51. }
  52.  
  53. catch (FormatException)
  54. {
  55. Console.WriteLine("ERROR: Number required");
  56. Console.WriteLine();
  57. goto Start;
  58. }
  59. numStore.Add(nextValue);
  60. } else
  61. {
  62. try
  63. {
  64. firstValue = Convert.ToDouble(Console.ReadLine());
  65. }
  66.  
  67. catch (FormatException)
  68. {
  69. Console.WriteLine("ERROR: Number required");
  70. Console.WriteLine();
  71. goto Start;
  72. }
  73. numStore.Add(firstValue);
  74. }
  75.  
  76. if(i != numAmount)
  77. {
  78. Console.Write("Equation mark(+,-,*,/): ");
  79. equationMark = Convert.ToString(Console.ReadLine());
  80. }
  81.  
  82. if (equationMark == "+" || (equationMark == "-" || (equationMark == "*" || (equationMark == "/"))))
  83. {
  84. if (equationMark == "+")
  85. {
  86. firstValue = firstValue + nextValue;
  87. }
  88.  
  89. if (equationMark == "-")
  90. {
  91. equationCount = 2;
  92. }
  93.  
  94. if (equationMark == "*")
  95. {
  96. equationCount = 3;
  97. }
  98.  
  99. if (equationMark == "/")
  100. {
  101. equationCount = 4;
  102. }
  103. } else
  104. {
  105. Console.WriteLine("ERROR: Invalid equation mark.");
  106. Console.WriteLine();
  107. goto Start;
  108. }
  109. Console.WriteLine();
  110. }
  111. Console.WriteLine("Result: " + firstValue);
  112. Console.ReadKey();
  113. }
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment