修改下列代码中的错误: #include <iostream> using namespace std; int main () {int n; cin<<n<<endl;; if(n==1){cout<<"hero is idleling..."<<endl; cout<<"hero is attack..."<<endl; cout<<"hero is runing..."<<endl; cout<<"hero is dead..."<<endl;} else{cout<<"Monster is idleling..."<<endl; cout<<"Monster is attack..."<<endl; cout<<"Monster is runing..."<<endl; cout<<"Monster is dead..."<<endl;} }
时间: 2023-08-20 20:33:36 浏览: 88
使用include <iostream>时一定要加using namespace std
代码中的错误有:
1. `cin` 语句中应该使用 `>>` 而不是 `<<`。
2. 第三行代码中多了一个分号 `;`。
3. `if` 语句中缺少左大括号 `{`。
4. `else` 语句中缺少左大括号 `{`。
下面是修改后的代码:
```
#include <iostream>
using namespace std;
int main () {
int n;
cin >> n;
if(n == 1) {
cout << "hero is idleling..." << endl;
cout << "hero is attack..." << endl;
cout << "hero is runing..." << endl;
cout << "hero is dead..." << endl;
}
else {
cout << "Monster is idleling..." << endl;
cout << "Monster is attack..." << endl;
cout << "Monster is runing..." << endl;
cout << "Monster is dead..." << endl;
}
}
```
阅读全文