1. Adding 2 Numbers
2. Subtracting 2 Numbers
3. Multiplying 2 Numbers
4. Dividing 2 Numbers
এবং যতক্ষণ user program টি বন্ধ করতে না চাইবে ততোক্ষণ পর্যন্ত চালু থাকবে -
using System;
using System.Collections.Generic;
using System.Linq;
namespace MainPrograms
{
public class Program
{
public static void Main(string[] args)
{
string UserSelection = String.Empty;
do
{
PrintMenu();
int UserChoice = Convert.ToInt32(Console.ReadLine());
while (UserChoice<1 || UserChoice>4)
{
Console.WriteLine("Invalid Option, Try again");
PrintMenu();
UserChoice = Convert.ToInt32(Console.ReadLine());
}
Calculate(UserChoice);
Console.WriteLine("Do you want to continue");
UserSelection = Console.ReadLine();
while (UserSelection.ToUpper() != "YES" &&
UserSelection.ToUpper() != "NO")
{
Console.WriteLine();
Console.WriteLine("Invalid Input - Please type Yes or No");
Console.WriteLine("Do you want to continue");
UserSelection = Console.ReadLine();
}
}
while (UserSelection.ToUpper()!="NO");
Console.WriteLine();
Console.WriteLine("This program will be tarminated right
now give any character input");
Console.ReadLine();
}
private static void Calculate(int userChoice)
{
double Result = 0;
Console.WriteLine("Please enter your first number");
int firstNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter your second number");
int secondNumber = Convert.ToInt32(Console.ReadLine());
switch (userChoice)
{
case 1:
Result = firstNumber + secondNumber;
Console.WriteLine("{0}+{1}={2}", firstNumber, secondNumber, Result);
break;
case 2:
Result = firstNumber - secondNumber;
Console.WriteLine("{0}-{1}={2}", firstNumber, secondNumber, Result);
break;
case 3:
Result = firstNumber * secondNumber;
Console.WriteLine("{0}*{1}={2}", firstNumber, secondNumber, Result);
break;
case 4:
Result = firstNumber / secondNumber;
Console.WriteLine("{0}/{1}={2}", firstNumber, secondNumber, Result);
break;
}
}
private static void PrintMenu()
{
Console.WriteLine();
Console.WriteLine("Select your option");
Console.WriteLine("------------------");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
Console.WriteLine();
}
}
}
No comments:
Post a Comment