Jump to content

  • Log In with Google      Sign In   
  • Create Account

Parse Error?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
26 replies to this topic

#1 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 11:40 AM

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?

Sponsor:

#2 deadlinegrunt   Members   -  Reputation: 123

Like
Likes
Like

Posted 09 October 2001 - 12:20 PM

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.


#3 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 01:37 PM

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.



#4 Colin Jeanne   Members   -  Reputation: 1114

Like
Likes
Like

Posted 09 October 2001 - 01:57 PM

cout<<"you are"<} should be cout<<"you are";}

Invader X
Invader''s Realm

#5 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 02:03 PM

Oops, that was a mistake.
That line should read...

cout<<"you are"<}


#6 Anthracks   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 02:06 PM

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

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 09 October 2001 - 02:18 PM

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.


#8 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 02:36 PM

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?

#9 Null and Void   Moderators   -  Reputation: 1087

Like
Likes
Like

Posted 09 October 2001 - 02:46 PM

It is executing, it is just finishing because it doesn''t have to wait for anything. Make it get input or wait at the end of the program, then it won''t close when it''s done.

[Resist Windows XP''s Invasive Production Activation Technology!]

#10 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 04:11 AM

How do I make it wait?
I am not using return 0; or anything

#11 barazor   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 04:31 AM

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



#12 barazor   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 04:32 AM

oh, and also,
cin >> somefakevariable works pretty well, for example

char somefakevariable;
cin >> somefakevariable;

:D



#13 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 04:34 AM

Ok, thanks.
I just compiled a few things and they worked!

#14 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 07:53 AM

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.

#15 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 10 October 2001 - 08:02 AM

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.

#16 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 08:13 AM

I tried that and it still didn''t work. Here is the whole thing.
  #include <stdio.h>
#include <iostream.h>
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 "<<x<<".\n";
start();
}
void start()
{
cout<<"Welcome. Here is your first question.\n";
a();
}

int main(int argc, char *argv[])
{
cout<<"Welcome to the trivia game.\n";
cout<<"To play, type in a number 1-4 in accordance with the question.\n";
start();
}


#17 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 09:00 AM

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.

#18 RandomTask   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 09:07 AM

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.

RandomTask

#19 RandomTask   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 09:08 AM

Well, you musta posted right after I hit post reply!

RandomTask

#20 IRDumb   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 09:32 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS