Home » C programs » C common errors programs
Here, we will learn why an error Expected '}' before 'else' and how to fix it in C programming language? By IncludeHelp Last updated : March 10, 2024
Error: Expected '}' before 'else'
Error: Expected '}' before 'else' occurs, if closing scope curly brace of if statement is missing.
Consider the code:
Example
include
int main[] { int a = 10; if[a == 10] {
printf["Yes!\n"];
else
{ printf["No!\n"];
}
return 0;
}
Outputprog.cpp: In function ‘int main[]’: prog.cpp:10:2: error: expected ‘}’ before ‘else’ else ^~
How to fix?
See the code, closing curly brace } is missing before else statement. To fix this error - close the if statement's scope properly.
Correct Code
include
int main[] { int a = 10; if[a == 10] {
printf["Yes!\n"];
}
else
{ printf["No!\n"];
}
return 0;
}
OutputYes!
C Common Errors Programs »
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
- 08-05-2006
Registered User ---
oooo my bad the code right, hear line 21.
include
using namespace std;
int main[] { int pass;
cout pass; cin.ignore[]; if [ pass != 1098765432 ] { cout