Advertisement
phisut

EX1-2

Oct 22nd, 2014
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 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. float a = float.Parse(Console.ReadLine());
  15. Console.Write("\n");
  16. do{
  17. Console.Write("Input Opertor : ");
  18. string op = Console.ReadLine();
  19. calculate(op, ref a,ref x);
  20. } while (x != 0);
  21. Console.WriteLine("Finish calculation.");
  22. Console.Write("End Value is {0:f4}", a);
  23. Console.ReadLine();
  24. }
  25. static int calculate(string op, ref float a,ref int x)
  26. {
  27. float b;
  28. switch (op)
  29. {
  30. case "*": Console.Write("Input Number : ");
  31. b = float.Parse(Console.ReadLine());
  32. a = a * b;
  33. Console.WriteLine("Present Value = {0:f4} ", a);
  34. break;
  35. case "/": Console.Write("Input Number : ");
  36. b = float.Parse(Console.ReadLine());
  37. a = a / b;
  38. Console.WriteLine("Present Value = {0:f4} ", a);
  39. break;
  40. case "-": Console.Write("Input Number : ");
  41. b = float.Parse(Console.ReadLine());
  42. a = a - b;
  43. Console.WriteLine("Present Value = {0:f4} ", a);
  44. break;
  45. case "+": Console.Write("Input Number : ");
  46. b = float.Parse(Console.ReadLine());
  47. a = a + b;
  48. Console.WriteLine("Present Value = {0:f4} ", a);
  49. break;
  50. default: x = 0; break;
  51. } Console.WriteLine("\n");
  52. return x;
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement