#include using namespace std; int main() { int val1, val2; val1 = -5; val2 = -5; cout << "Val1: " << val1 << endl; cout << "Val2: " << val2 << endl; // example of the dangling else problem if (val1 > 0) if (val2 > 0) cout << "Statement 1a" << endl; else cout << "Statement 2a" << endl; // the compiler matches an else clause with the closest unmatched // if clause. This causes the above code to have an if-else // statement inside of an if statement (which is opposite of // how the code is indented. // The solution to have an if statement inside of an if-else // statement is to use curly braces if (val1 > 0) { if (val2 > 0) cout << "Statement 1b" << endl; } else cout << "Statement 2b" << endl; }