Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Tutorials
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numAmount = 0;
- int numCount = 0;
- int equationCount = 0;
- double firstValue = 0.0;
- double nextValue = 0.0;
- string equationMark;
- Start:
- numAmount = 0;
- numCount = 0;
- equationCount = 0;
- Console.Write("Write the amount of numbers: ");
- try
- {
- numAmount = Convert.ToInt32(Console.ReadLine());
- }
- catch (FormatException)
- {
- Console.WriteLine("ERROR: Number required");
- Console.WriteLine();
- goto Start;
- }
- Console.WriteLine();
- List < double > numStore = new List<double>();
- for (int i = 0; i < numAmount; i++)
- {
- numCount++;
- Console.Write("Number " + numCount + ": ");
- if(i%2 == 0)
- {
- try
- {
- nextValue = Convert.ToDouble(Console.ReadLine());
- }
- catch (FormatException)
- {
- Console.WriteLine("ERROR: Number required");
- Console.WriteLine();
- goto Start;
- }
- numStore.Add(nextValue);
- } else
- {
- try
- {
- firstValue = Convert.ToDouble(Console.ReadLine());
- }
- catch (FormatException)
- {
- Console.WriteLine("ERROR: Number required");
- Console.WriteLine();
- goto Start;
- }
- numStore.Add(firstValue);
- }
- if(i != numAmount)
- {
- Console.Write("Equation mark(+,-,*,/): ");
- equationMark = Convert.ToString(Console.ReadLine());
- }
- if (equationMark == "+" || (equationMark == "-" || (equationMark == "*" || (equationMark == "/"))))
- {
- if (equationMark == "+")
- {
- firstValue = firstValue + nextValue;
- }
- if (equationMark == "-")
- {
- equationCount = 2;
- }
- if (equationMark == "*")
- {
- equationCount = 3;
- }
- if (equationMark == "/")
- {
- equationCount = 4;
- }
- } else
- {
- Console.WriteLine("ERROR: Invalid equation mark.");
- Console.WriteLine();
- goto Start;
- }
- Console.WriteLine();
- }
- Console.WriteLine("Result: " + firstValue);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment