Jump to content
  • Advertisement
Sign in to follow this  
jason1

parse error

This topic is 4681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

whats a parse error. i tried to make a program and it came up with a parse error at "return 0;"

Share this post


Link to post
Share on other sites
Advertisement
A parse error means the compiler can't figure out what you mean. It generally involves an illegal sequence of keywords, identifiers or operators.

Share this post


Link to post
Share on other sites
im makin a game, its simple but im makin it because i just want to refrest wat ive learned. im doin it in parts and im going to later put it together here's what the part messin up is:



#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
int randomNumber = rand();
int die = (randomNumber % 2) + 1;

cout << "You get in a fight.";

if (die = 1)
cout << "You lost the fight.";

if (die = 2)
cout << "You won the fight!"

return 0;
}

Share this post


Link to post
Share on other sites
You forgot a semi-colon after the end of cout << "You won the fight!". Also your if statements should have == instead of =.

Share this post


Link to post
Share on other sites
The == Operator is used to compare an equality
when the = Operator is used to ( i beleive the word is Increment )

Like doing

iNumber = 1;

iNumber become 1;

Share this post


Link to post
Share on other sites
Quote:
Original post by deathwearer
The == Operator is used to compare an equality
when the = Operator is used to ( i beleive the word is Increment )

== compares
assigns

Share this post


Link to post
Share on other sites
You didn't seed the random number generator. You need to call srand() with a different number each run to have different results. A popular method is to use srand(time());

Share this post


Link to post
Share on other sites
Quote:
Original post by jason1
it always go to "You won the fight!". how do i fix this?


Because if you always use rand() alone like that it will always give you the same number.

Just add

#include <time.h>

and before you call rand() do

srand(time(0));

And also you might want to add a min and max number to random.

randomNumber = rand()%7+1;

Will randomize a number between 1 and 7


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!