Advertisement
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 lr1
- {
- class Program
- {
- static void Main(string[] args)
- {
- float num1 = 0, num2 = 0, res = 0;
- string op = "";
- bool show_res;
- do
- {
- show_res = true;
- do // check if data is correct
- {
- Console.Write("Enter 1st number: ");
- } while (!float.TryParse(Console.ReadLine(), out num1));
- do // check if data is correct
- {
- Console.Write("Enter 2nd number: ");
- } while (!float.TryParse(Console.ReadLine(), out num2));
- Console.Write("Choose operation from {/, *, -, +}: ");
- op = Console.ReadLine();
- switch (op)
- {
- case "+":
- res = num1 + num2;
- break;
- case "-":
- res = num1 - num2;
- break;
- case "*":
- res = num1 * num2;
- break;
- case "/":
- if (num2 != 0)
- res = num1 / num2;
- else
- {
- Console.WriteLine("Error: Division by zero!");
- show_res = false;
- }
- break;
- default: // if data is incorrect
- Console.WriteLine("Non-existent option chosen, try again!");
- show_res = false;
- break;
- }
- if (show_res)
- Console.WriteLine(String.Format("{0}{1}{2} = {3}", num1, op, num2, res));
- Console.Write("\nEnter 0 to exit or nothing to continue: ");
- } while (Console.ReadLine() != "0");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement