Advertisement
Guest User

Ex!1รอบ2

a guest
Oct 22nd, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication7
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int x=-1;
  13.             Console.Write("\nInput Value : ");
  14.             int a = int.Parse(Console.ReadLine());
  15.             do{
  16.                 Console.Write("Input Opertor : ");
  17.                 string op = Console.ReadLine();
  18.                 calculate(op, ref a,ref x);
  19.               } while (x != 0);
  20.         Console.Write("End Value is {0}",a);
  21.         Console.ReadLine();
  22.         }
  23.         static int calculate(string op, ref int a,ref int x)
  24.         {
  25.            int b;
  26.            switch (op)
  27.             {
  28.                 case "*": Console.Write("Input Number : ");
  29.                     b = int.Parse(Console.ReadLine());
  30.                     a = a * b;
  31.                     Console.WriteLine("Present Value = {0} ", a);
  32.                     break;
  33.                 case "/": Console.Write("Input Number : ");
  34.                     b = int.Parse(Console.ReadLine());
  35.                     a = a / b;
  36.                     Console.WriteLine("Present Value = {0} ", a);
  37.                     break;
  38.                 case "-": Console.Write("Input Number : ");
  39.                     b = int.Parse(Console.ReadLine());
  40.                     a = a - b;
  41.                     Console.WriteLine("Present Value = {0} ", a);
  42.                     break;
  43.                 case "+": Console.Write("Input Number : ");
  44.                     b = int.Parse(Console.ReadLine());
  45.                     a = a + b;
  46.                     Console.WriteLine("Present Value = {0} ", a);
  47.                     break;
  48.                 default: x = 0; break;
  49.                 }
  50.             return a;
  51.        
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement