Help I don't know whats wrong! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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"; ^~~~"

2nd Mar 2019, 2:22 PM
XammerJ777
XammerJ777 - avatar
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... }
2nd Mar 2019, 2:35 PM
Gordon
Gordon - avatar