New course! Every coder should learn Generative AI!
Try a free lesson0
Help I don't know whats wrong!
#include <iostream> using namespace std; int main() { int a ; cin >> a; if(a > 99); if(a < 101); cout << "Granted! \n"; else cout << "Denied! \n"; return 0; } ___________________________________________________ Trying to run it but it says "..\Playground\: In function 'int main()': ..\Playground\:15:5: error: 'else' without a previous 'if' else cout << "Denied! \n"; ^~~~"
1 Answer
+ 3
1. Don't use semicolon after the condition of if.
Instead use brackets to contain the code block.
For example,
if(4>3){
... code block for true...
}
2. When you have two conditions, join them with and or or
For example
4<8&&5>6
3. Use else after closing bracket of if and use brackets to contain the code block for false.
For example,
if(...){
} else{
.... Code block for false...
}