برنامه ای جهت محاسبه ی چهار عمل اصلی
ب
namespace ConsoleApplication1 { class Program { // Created By Mohammadreza Bitarafan // static void Main(string[] args) { Menu.ShowMenu(); Console.ReadKey(); Console.Clear(); } } } |
class Calculator { public static void Sum() { Console.Write("Enter Your First Number:"); double Number1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Your Second Number:"); double Number2=Convert.ToDouble(Console.ReadLine()); double sum = Number1 + Number2; Console.WriteLine(sum); } public static void Sub() { Console.Write("Enter Your First Number:"); double Number1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Your Second Number:"); double Number2 = Convert.ToDouble(Console.ReadLine()); double sub = Number1 - Number2; Console.WriteLine(sub); } public static void Mul() { Console.Write("Enter Your First Number:"); double Number1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Your Second Number:"); double Number2 = Convert.ToDouble(Console.ReadLine()); double mul = Number1 * Number2; Console.WriteLine(mul); } public static void Div() { Console.Write("Enter Your First Number:"); double Number1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Enter Your Second Number:"); double Number2 = Convert.ToDouble(Console.ReadLine()); double div = Number1 / Number2; Console.WriteLine(div); } } |
class Menu { public static void ShowMenu() { Console.WriteLine("Enter Your Choice:"); Console.WriteLine("1)Sum"); Console.WriteLine("2)Sub"); Console.WriteLine("3)Mul"); Console.WriteLine("4)Div"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: Calculator.Sum(); break; case 2: Calculator.Sub(); break; case 3: Calculator.Mul(); break; case 4: Calculator.Div(); break; } } |