返回列表 發帖

[4-7]進階計算機

  1. using static System.Formats.Asn1.AsnWriter;


  2. double num1, num2;
  3. string oper;
  4. re:
  5. System.Console.Write("請輸入第一個數:");
  6. num1 = System.Convert.ToDouble(System.Console.ReadLine());

  7. System.Console.Write("請輸入要做的運算(+、-、*、/) : ");
  8. oper= System.Console.ReadLine();   

  9. System.Console.Write("請輸入第二個數:");
  10. num2 = System.Convert.ToDouble(System.Console.ReadLine());

  11. if (oper == "+")
  12.     System.Console.WriteLine(num1 + " + " + num2 + " = " + (num1 + num2));

  13. else if (oper == "-")
  14.     System.Console.WriteLine(num1 + " - " + num2 + " = " + (num1 - num2));

  15. else if (oper == "*")
  16.     System.Console.WriteLine(num1 + " * " + num2 + " = " + (num1 * num2));

  17. else if (oper == "/")
  18.     System.Console.WriteLine(num1 + " / " + num2 + " = " + (num1 / num2));

  19. else
  20.     System.Console.WriteLine("不合法的運算符號");

  21. goto re;
複製代碼
istak.teach2@gmail.com

返回列表