Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

main.cpp:2:1: error: expected initializer before ‘if’

+3 votes
asked Sep 16 by Pedro Henrique (150 points)
hello, I want to solve a problem with 'if' I'm creating a test in C++ online, but it always gives error "main.cpp:2:1: error: expected initializer before 'if'" here is the test source code: int cell
 if(mobile)
I using mobile Android Phone, Yes, is simples test for Miner Game.

1 Answer

0 votes
answered Sep 17 by Peter Minarik (58,220 points)

Are you missing a semicolon (;) from the end of the last line?

int cel;

commented Sep 17 by Pedro Henrique (150 points)
This not is original code.
I already put the comma and had the same problem.
Original Code Here:
int celular
if(celular)
commented Sep 17 by Peter Minarik (58,220 points)
Can you save your project and share a link?

Your shared code has the same problem: at the end of "int celular" there is a missing semicolon.
commented Sep 17 by Pedro Henrique (150 points)
No, has no way...
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...