+ 4
1st Nov 2024, 2:51 AM
Shashikant Pandey
Shashikant Pandey - avatar
8 ответов
+ 3
Try this: #include <iostream> #include <sstream> using namespace std; void Calculator(float num1, char op, float num2) { float result; switch (op) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': result = num1 / num2; break; default: cout << "Please Enter Correct Operation"; return; } cout << result; } int main() { string input; getline(cin, input); istringstream iss(input); float num1, num2; char op; if (iss >> num1 >> op >> num2) { Calculator(num1, op, num2); } else { cerr << "Invalid input format." << endl; } }
1st Nov 2024, 3:40 AM
Jerry Hobby