Board logo

標題: [4-7]進階計算機 [打印本頁]

作者: 李泳霖    時間: 2023-11-22 11:36     標題: [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;
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2