[HELP]How do I break between If else on C++?
Go to solution
Solved by MSVSora,
2 minutes ago, rcarlos243 said:I have no idea how to do it
A switch case is written by doing the following
//enums also work here switch(integer variable) { case integer value: //code here break; case integer value2: //code here break; default: //code here break; }
Though this wouldn't help you much, personally I would write the code something like this
const int maxNrOfTrys = 5; for (int i = 0; i > 0; i = maxNrOfTrys; --i) { cout << "Enter your password "; getline(cin, input); if ( input == "P@ssw0rd") { cout << "In " << years << " years, $" << D << " deposited per month will grow to $" << S ; break; } else { cout << "incorrect, password! " << i <<" more try limit\n"; } }
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now