Faster way to write if statements?

hello, i am obviously a beginner here and im writing a program thats like a small text adventure that gives a location and asks what direction to go:

cout << "You are in a long hallway, what do you do?\nleft, right, forward\n" << endl;
cin >> a;

if(a==left){
cout << "other location\ndirection direction"...
}
if(a==right) if(a==forward)

and i was wondering if there was a way to save time on writing if statements, or would i just have to write an if statement for every direction and have if's inside of if's?
Last edited on
You can use a switch statement.

Check out the reference documentation section at top left of this page. There is a tutorial that has all kinds of good info.

Hope all goes well. :)
Only use a switch/case if you are 'choosing'. The difference between a switch/case and an if() statement is that with a switch statement, it is a 1-input/1-output. This is more efficient than doing the same thing with an if() statement.

The advantages, however, of an if() statement are that you can have more than 1 condition with an if() statement, and any number of outputs.

Also, i think switch/case statements compile a lot differently in terms of interpreting conditions. In some cases, every case was triggered, and I ended up re-writing the conditional terms in If() statements instead (and it worked like a charm...).
Topic archived. No new replies allowed.