gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
帮我写一个C++计算器
- User
帮我写一个C++计算器
- Assistant
Sure! Here is a simple example of a calculator in C++:
#include <iostream> using namespace std; int main() { char operation; float num1, num2; cout << "Enter first number: "; cin >> num1; cout << "Enter operation (+, -, *, /): "; cin >> operation; cout << "Enter second number: "; cin >> num2; switch(operation) { case '+': cout << "Result: " << num1 + num2; break; case '-': cout << "Result: " << num1 - num2; break; case '*': cout << "Result: " << num1 * num2; break; case '/': if (num2 != 0) { cout << "Result: " << num1 / num2; } else { cout << "Error: Division by zero."; } break; default: cout << "Invalid operation."; break; } return 0; }This calculator program prompts the user to enter two numbers and an operation (+, -, *, /), then performs the calculation and displays the result. It also handles divide by zero errors. Feel free to customize and expand on this example as needed!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.