#include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2;
cout << "輸入運算子:+、-、*、/ : ";
cin >> op;
cout << "輸入兩個數: ";
cin >> num1 >> num2;
switch(op)
case "+":
cout << num1+num2;
break;
case "-":
cout << num1-num2;
case "*":
cout << num1*num2;
case "/":
cout << num1/num2;
default:
// 如果運算子不是 +, -, * 或 /, 提示錯誤資訊
cout << "Error! 請輸入正確運算子。";
}
return 0;
#include <iostream>
using namespace std;
int main()
{
char op;
float num1, num2;
cout << "輸入運算子:+、-、*、/ : ";
cin >> op;
cout << "輸入兩個數: ";
cin >> num1 >> num2;
switch(op)
{
case "+":
cout << num1+num2;
break;
case "-":
cout << num1-num2;
break;
case "*":
cout << num1*num2;
break;
case "/":
cout << num1/num2;
break;
default:
// 如果運算子不是 +, -, * 或 /, 提示錯誤資訊
cout << "Error! 請輸入正確運算子。";
break;
}
return 0;
}