Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#include
using namespace std;
int main() {
int num1, num2;
int choice;
cout << "请输入第一个整数: ";
cin >> num1;
cout << "请输入第二个整数: ";
cin >> num2;
cout << "请选择操作:" << endl;
cout << "1. 加法" << endl;
cout << "2. 减法" << endl;
cout << "请输入你的选择 (1 或 2): ";
cin >> choice;
if (choice == 1) {
int result = num1 + num2;
cout << "结果: " << num1 << " + " << num2 << " = " << result << endl;
} else if (choice == 2) {
int result = num1 - num2;
cout << "结果: " << num1 << " - " << num2 << " = " << result << endl;
} else {
cout << "无效的选择,请输入 1 或 2。" << endl;
}
}#include
using namespace std;
(2)
int main() {
int number;
cout << "请输入一个整数: ";
cin >> number;
if (number % 2 == 0) {
cout << number << " 是偶数。" << endl;
} else {
cout << number << " 是奇数。" << endl;
}
}#include
#include // 包含 rand() 和 srand() 函数
#include // 包含 time() 函数
using namespace std;
(3)
int main() {
srand(static_cast(time(0)));
int secretNumber = rand() % 10 + 1;
int guess;
int attempts = 0;
}