• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Parse Error?

## 26 posts in this topic

Whenever I try and compile my code on dev-cpp, I get all these parse error, like on my bracket ({) or something. It says something like this... parse error before ''<'' parse error before ''['' and so on... What is going on?
0

##### Share on other sites
You haven''t given enough information for anybody to help you specifically. The only advice I can give is to start at the top of your error list, not the bottom.
0

##### Share on other sites
Ok, well try this...

(I just did this right now in my compiler, dev)

#include
void main()
{
int age
cout<<"hello world\n";
cout<<"how old are you?\n";
cin>>age;
cout<<"you are"<}

The only error I got was "parse error before <''" in line 5.
Also, when I said, "execute" nothing happened, even though the
box was saying execute.

0

##### Share on other sites
cout<<"you are"<} should be cout<<"you are";}

0

##### Share on other sites
Oops, that was a mistake.

cout<<"you are"<}
0

##### Share on other sites
You need to put a semi-colon ";" after int age...

Also, use the tags [ source ] and [ /source ] (without the extra spaces) around any code you post so it doesn''t think the less than/greater than signs are HTML.

Anthracks
0

##### Share on other sites
Hmm, you should read the FAQ. It explains how to post code without having things get eaten by HTML by using certain special tags. I forget what they are at the moment.

As far as the code you posted, it looks like you''re missing a ; on line 4 after "int age". With C/C++, when the compiler gives an error on a specific line, the problem isn;t necessarily on that line. Often incorrect code on previous lines can''t be detected and reported by the compiler until it reachs a point on a later line.
0

##### Share on other sites
Ok, thanks
After the semicolon it was fine, so I guess I just miss semicolons and stuff. And I''ll do that
  
next time too.
Now another thing-
*Why does''t the program execute even after I compile it no errors? What happens is I click execute, and the top blue status/tool bar thing goes from blue to gray and then returns?
0

##### Share on other sites
How do I make it wait?
I am not using return 0; or anything
0

##### Share on other sites
either include stdlib.h and use system("PAUSE") at the end of the program, or include stdio and use getchar()

0

##### Share on other sites
oh, and also,
cin >> somefakevariable works pretty well, for example

char somefakevariable;
cin >> somefakevariable;

:D

0

##### Share on other sites
Ok, thanks.
I just compiled a few things and they worked!
0

##### Share on other sites
Ok, now I have a new error.
When I try this...
  if(pick1==2) { cout<<"You''re right!\n"; x=x+1; b(); }else if(pick1!=2) { cout<<"Wrong. The correct answer was 2.\n"; b(); }} 

after a question in my trivia game, it compiles with zero errors but after I answer the question in the dos program, it always says wrong no matter what I typed in. Is it a problem with my if/else if statement?

Oh, FYI, "x" is the results thing and "pick1" is the choice they enter.
0

##### Share on other sites
Again, we need a little more information to help you, such as the type of pick1 (I''ll just assume it''s an int) and the scope of the if-elseif statement black. However, here''s a little tip: since "2" is the only correct answer, do:
if(pick1 == 2){  cout << "You''re right!\n";  // ++x, x++, x+= 1 and x = x+1 are similar.  // Since you don''t care whether it happens before  // or after this statment, use ++x;  ++x;  b();}else{  cout << "Sorry, the answer is 2.\n";   b();} 

The other thing is make sure your pick1 is an integer (int); if it''s a char then it wont behave the way you expect.
0

##### Share on other sites
I tried that and it still didn''t work. Here is the whole thing.
  #include #include void a();void b();void c();void start();void results();int pick, x;void a(){int pick1;cout<<"How many bones are in the human body?\n";cout<<"1. 100\n";cout<<"2. 206\n";cout<<"3. 266\n";cout<<"4. Over 1000\n";cin>>pick;pick=pick1;if(pick1==2) { cout<<"You''re right!\n"; ++x; b(); }else { cout<<"Wrong. The correct answer was 2.\n"; b(); }}void b(){int pick2;cout<<"What is the name of our currenet president?\n";cout<<"1. Ronald Reagan\n";cout<<"2. John Kennedy\n";cout<<"3. Bill Clinton\n";cout<<"4. George Bush\n";cin>>pick;pick=pick2;if(pick2==4) { cout<<"You''re right!\n"; ++x; c(); }else { cout<<"Wrong. The correct answer was 4.\n"; c(); }}void c(){int pick3;cout<<"What is 12x12?\n";cout<<"1. 100\n";cout<<"2. 122\n";cout<<"3. 144\n";cout<<"4. 1212\n";cin>>pick;pick=pick3;if(pick3==3) { cout<<"You''re right!\n"; ++x; results(); }else { cout<<"Wrong. The correct answer was 3.\n"; results(); }}void results(){cout<<"Your score was "<
0

##### Share on other sites
I really am stupid.
All I had to do was take out int pick at the top and pick=pick 3 etc. and it worked fine! Thank you guys for all your help.
0

##### Share on other sites
Ok, here is what you have:

  int pick1;cout<<"How many bones are in the human body?\n";cout<<"1. 100\n";cout<<"2. 206\n";cout<<"3. 266\n";cout<<"4. Over 1000\n";cin>>pick;pick=pick1;if(pick1==2){ cout<<"You''re right!\n"; ++x; b();}else{ cout<<"Wrong. The correct answer was 2.\n"; b();}

Look at these two lines in particular:
  cin>>pick;pick=pick1;

it should be:
  pick1=pick;

otherwise you overwrite the value you read in with the uninitialized value that was in pick1 when the routine was put on the stack.

Remeber your assignment ordering. The variable to left of the operator receives the value from the variable to the right of the operator.

0

##### Share on other sites
Well, you musta posted right after I hit post reply!

0

##### Share on other sites
Ok, I promise, this is the last parse error. I added a lot to the program and I can get it down to one error:
Parse error at end of input

I didn''t change int main() at all so why is it saying parse error at end of input?
I would post the new thing up there but it is really long(like 175 lines) so if you can help, thanks.
My e-mail is "Rick__33@hotmail.com" if you want to see it.
0

##### Share on other sites
Never mind, got it. Thanks anyways.
0

##### Share on other sites
Another thing I find interesting is that you''re chaining your functions, which is bad (it uses up stack space, but for now just know that it''s bad.) Here''s a new main() for you:
bool not_done = true;// don''t worry about argc and argvint main(int argc, char *argv[]){  while(not_done)  {      cout<< "Welcome to the trivia game.\n";    cout<< "To play, type in a number 1-4 in accordance with the question.\n";    start();    a();    b();    c();    result();    // add some code to ask the use if he want to quit or play again  }}

Remove the calls to the other functions inside your current functions (ie, don''t have a() call b() and so forth.) You can''t escape the while loop because the way you currently link your functions will eventually blow your stack (you''ll run out of memory for your program.)

Now as for the parse error, check all your punctuations - semicolons at the end of every line, etc.
0

##### Share on other sites
Ok, I''ll change the format later tonight.
One thing I don''t really understand is what bool means. How is it used in code?
0

##### Share on other sites
bool means Boolean (named after the mathematician George Boole - at least I think it was George...), and are variables that evaluate to "true" or "false." Until bool became a part of the C++ language, programmers usually defined their own custom boolean type (which was either an entire integer or a bit in a bitfield); the Win32 API even has BOOL defined!

All you need to know is that a variable of type bool can either be true or false (and you assign "true" or "false" to them like in my example), which means you can use them in branching:
if(boolean_condition){  do_something;}else{  do_something_else;}
0

##### Share on other sites
Ok, I kind of knew that.
I re-did my program and it works just as good. (8 questions now!)
I was wondering, can i add sound to a dos program? And if so, how?
0