#include <iostream>
using namespace std;
int main()
{
int happy = 1, HAPPY = 2; // refer to my comments after this code
int pass;
cin >> pass >> endl; // no quotes around pass, and it is endl (an L) not a 1
if (pass == happy || pass == Happy) {
// ^ need opening { and you don't put a ; on same line as an if, otherwise the if does nothing
cout << "welcome!" << endl;
} else {
cout << "incorrect user ID" << endl;
}
return 0;
}
Oh, I thought that you would put else if, if there was more than two executable conditions.
example:
if (condition)
else if (condition2)
else (condition3)
if(pass == happy) {
cout << "welcome user!" << endl;
} else if(pass == HAPPY) {
cout << "welcome other user!" << endl;
} else {
cout << "incorrect password" << endl;
}
Desoxena wrote:Oh, I thought that you would put else if, if there was more than two executable conditions.
example:
if (condition)
else if (condition2)
else (condition3)
if (something)
{
// look busy
}
else
if (something else)
{
//slave away
}
Desoxena wrote:Well in that last code you showed, wouldn't you have to put a cin for console input? So the user could even enter a password for the program to even run?
thetan wrote:In the C standard, there is no such thing as an else if statement and instead it only exists by convention.
Assassian360 wrote:His code that he has shown is in a traditionally C++ approach, so I decided to assume he is using C++ which does include the "else if" natively. It is a valid point though if he should ever decide to learn C as well, or any other language that doesn't include "else if" natively.
// roughly formatted in Bison style BNF
statement = conditonal
| for-loop
| while-loop
......
;
conditional = IF condition statement
| IF condition statement ELSE statement
;
thetan wrote:NOTE: i trolled the shit out of kiyoura with that one day "hey br0, have you heard the newest gcc extension supports the else-while statement" and i linked him to some code that litterally had an else-while statement that compiled and he was amazed, but i couldn't keep the trolling up, so i told a friend of mine and he lol'd him to hell and back <3
Users browsing this forum: No registered users and 0 guests