Mình đang chạy chương trình bằng C++ gặp lỗi:
Expected unqualified-id before 'if'.
Mình chưa thông thạo C++ lắm. Mình không biết cách khắc phục lỗi này, nhờ các bạn giúp. Chạy trên Dev C++.
#include<iostream>
#include<string>
using namespace std;
int main(){
int a;
string n;
cout <<"This is first time you use this os?Y/n"<<endl;
cin >> n;
if (n == "n"){
string loginname;
cout <<"What is your login name: "<<endl;
cin >> loginname;
cout <<"Hello, "<<loginname<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
}
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
if (a == '2'){
string signupname;
string email;
string newpassword;
cout <<"What is your name: "<<endl;
cin >>signupname;
cout <<"Ok,you are "<<signupname<<" What is your email?"<<endl;
cin >> email;
cout <<"Now,please enter your password"<<endl;
cin >> newpassword;
cout <<"Name: "<<signupname<<"Email: "<<email<<"Password: "
<<newpassword<<endl;
cout<<"Welcome, "<<signupname<<endl;
cout <<"Thanks to use NitroOs!"<<endl;
cout <<"We hope this operating system will make you more comvienice and it will be more powerful!"<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
} if (a == '1'){
cout <<"Now you use this system as guest,you maybe got some unconvinice,but we hope you got comfortable with it"<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
}
if (a == '3'){
string loginname;
cout <<"What is your login name: "<<endl;
cin >> loginname;
if (loginname == "Tuan"){
cout <<"Hello, "<<loginname<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
}
}
if (n == "n"){ // Lỗi từ đây
string signupname;
string email;
string newpassword;
cout <<"What is your name: "<<endl;
cin >>signupname;
cout <<"Ok,you are "<<signupname<<" What is your email?"<<endl;
cin >> email;
cout <<"Now,please enter your password"<<endl;
cin >> newpassword;
cout <<"Please re-enter your password"<<endl;
cin >> newpassword;
cout <<"Name: "<<signupname<<"Email: "<<email<<"Password: "<<newpassword<<endl;
cout<<"Welcome, "<<signupname<<endl;
cout <<"Thanks to use NitroOs!"<<endl;
cout <<"We hope this operating system will make you more comvienice and it will be more powerful!"<<endl;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;}
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
if (a == '2'){
string signupname;
string email;
string newpassword;
cout <<"What is your name: "<<endl;
cin >>signupname;
cout <<"Ok,you are "<<signupname<<" What is your email?"<<endl;
cin >> email;
cout <<"Now,please enter your password"<<endl;
cin >> newpassword;
cout <<"Name: "<<signupname<<"Email: "<<email<<"Password: "<<newpassword<<endl;
cout<<"Welcome, "<<signupname<<endl;
cout <<"Thanks to use NitroOs!"<<endl;
cout <<"We hope this operating system will make you more convienice and it will be more powerful!"<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
if (a == '1'){
cout <<"Now you use this system as guest,you maybe got some unconvinice,but we hope you got comfortable with it"<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
if (a == '1'){
cout <<"Now you use this system as guest,you maybe got some unconvinice,but we hope you got comfortable with it"<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
if (a == '3'){
string loginname;
cout <<"What is your login name: "<<endl;
cin >> loginname;
if (loginname == "Tuan"){
cout <<"Hello, "<<loginname<<endl;
string command;
cout <<"Enter your command: "<<endl;
cin >> command;
if (command == "loginname"){
cout <<"You are "<<loginname<<endl;
if (command == "exit"){
cout <<"Ok,you got exited the os,now you can choose 3 selection"<<endl;
cout<<"1.Use as guest"<<endl;
cout <<"2.Create a new account"<<endl;
cout <<"3.Login if you have a NOs account"<<endl;
cin >> a;
}
}
}
}
return 0;
}
}
}
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?