Open itsshivamku opened 1 year ago
int main() { char operation; double num1, num2, result;
// Input the numbers and the operation std::cout << "Enter the first number-"; std::cin >> num1; std::cout << "Enter the second number-"; std::cin >> num2; std::cout << "Enter the operation (+, -, *, /):"; std::cin >> operation; // Perform the selected operation switch (operation) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case '/': if (num2 != 0) { result = num1 / num2; } else { std::cout << "Error: Cannot divide by zero.\n"; return 1; // Exit with an error code } break; default: std::cout << "Error: Invalid operation.\n"; return 1; // Exit with an error code } // Output the result std::cout << "Result: " << result << std::endl; return 0; // Exit normally
}
include
include
int main() { char operation; double num1, num2, result;
}