473,763 Members | 5,412 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with code (parse error)

Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Unti tled1.c parse error before "top_x"
28 C:\c\Rooms\Unti tled1.c parse error before "first_square_x "
35 C:\c\Rooms\Unti tled1.c parse error before '}' token

Why are these happening?

int room_square[25][20], selected = 1, squares = 1, first_square_x
= -1, first_square_y = 1;
void scr_make_room(v oid) //Make a room
{
int top_x, roomx, top_y, roomy, xplus, yplus;

top_x = 8; //floor(random(21 ))+1 //Do this later when
roomx = 5; //floor(random(8) )+1 //I can use random()
top_y = 12; //floor(random(16 ))+1 // and floor()
roomy = 5; //floor(random(8) )+1

//Turn all the wall squares within the room to floor
for (xplus = 0; xplus < roomx; xplus++)
{
for (yplus = 0; yplus < roomy; xplus++)
{

// make sure it's in the room
20: if top_x + xplus < 24 && top_y + yplus < 19 //***PARSE
ERROR
{
if room_square[top_x+xplus][top_y+yplus] == 0 //if
there is wall
{
room_square[top_x+xplus][top_y+yplus] = 1; //make
it floor
squares+=1; //increase the number of squares made

//record the first square made(ever)
28: if first_square_x == -1 //***PARSE ERROR
{
first_square_x = top_x+xplus;
first_square_y = top_y+yplus;
}//endi
}//endi wall
}//endi in room
35: }//end for y //***PARSE ERROR
}//end for x
}//end scr_make_room()

int main()
{
int i, j;

for (i = 0; i < 25; i++)
{
for (j = 0; j < 20; i++)
{
room_square[i][j]=0;
}
}

for (i=0; i<5; i+=1) //make 5 rooms
{
scr_make_room() ;
}

return 0;
}

Sep 30 '06 #1
21 2936
BWIGLEY wrote:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Unti tled1.c parse error before "top_x"
28 C:\c\Rooms\Unti tled1.c parse error before "first_square_x "
35 C:\c\Rooms\Unti tled1.c parse error before '}' token

Why are these happening?
Because you have omitted the parentheses in the if(...)
construct. They are not optional.

if (x < y) /* pass "Go," collect $200 */

if x < y /* go to jail. go directly to jail. */

--
Eric Sosman
es*****@acm-dot-org.invalid
Sep 30 '06 #2
BWIGLEY wrote:
Basically I've just started making a game. So far it makes an array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Unti tled1.c parse error before "top_x"
28 C:\c\Rooms\Unti tled1.c parse error before "first_square_x "
35 C:\c\Rooms\Unti tled1.c parse error before '}' token

Why are these happening?

int room_square[25][20], selected = 1, squares = 1, first_square_x
= -1, first_square_y = 1;
void scr_make_room(v oid) //Make a room
{
int top_x, roomx, top_y, roomy, xplus, yplus;

top_x = 8; //floor(random(21 ))+1 //Do this later when
roomx = 5; //floor(random(8) )+1 //I can use random()
top_y = 12; //floor(random(16 ))+1 // and floor()
roomy = 5; //floor(random(8) )+1

//Turn all the wall squares within the room to floor
for (xplus = 0; xplus < roomx; xplus++)
{
for (yplus = 0; yplus < roomy; xplus++)
{

// make sure it's in the room
20: if top_x + xplus < 24 && top_y + yplus < 19 //***PARSE
ERROR
if (top_x + xplus < 24 && top_y + yplus < 19) /* You need the
parenthesis */

Robert Gamble

Sep 30 '06 #3
"Eric Sosman" <es*****@acm-dot-org.invalidwrot e in message
news:Me******** *************** *******@comcast .com...
BWIGLEY wrote:
Basically I've just started making a game. So far it makes an
array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Unti tled1.c parse error before "top_x"
28 C:\c\Rooms\Unti tled1.c parse error before "first_square_x "
35 C:\c\Rooms\Unti tled1.c parse error before '}' token

Why are these happening?

Because you have omitted the parentheses in the if(...)
construct. They are not optional.

if (x < y) /* pass "Go," collect $200 */

if x < y /* go to jail. go directly to jail. */
Thanks. Anyone know why it crashes when I try to run it?
Sep 30 '06 #4
"BWIGLEY" <bw*****@ihug.c o.nzwrote in message
news:ef******** **@lust.ihug.co .nz...
"Eric Sosman" <es*****@acm-dot-org.invalidwrot e in message
news:Me******** *************** *******@comcast .com...
BWIGLEY wrote:
Basically I've just started making a game. So far it makes an
array
25 by 20 and tries to make five rooms within it.
In scr_make_room() there's parse errors:
20 C:\c\Rooms\Unti tled1.c parse error before "top_x"
28 C:\c\Rooms\Unti tled1.c parse error before "first_square_x "
35 C:\c\Rooms\Unti tled1.c parse error before '}' token
>
Why are these happening?
Because you have omitted the parentheses in the if(...)
construct. They are not optional.

if (x < y) /* pass "Go," collect $200 */

if x < y /* go to jail. go directly to jail. */

Thanks. Anyone know why it crashes when I try to run it?
OK, it's crashing because it's trying to put "0" in lots of memory in:

for (i = 0; i < 25; i++)
{
for (j = 0; j < 20; i++)
{
room_square[i][j]=0;
}
}

i just keeps going up. What's wrong with it.
Sep 30 '06 #5
BWIGLEY wrote:
Thanks. Anyone know why it crashes when I try to run it?
You are incrementing i when you mean to increment j.
Sep 30 '06 #6

"jmcgill" <jm*****@email. arizona.eduwrot e in message
news:gklTg.500$ rS.250@fed1read 05...
BWIGLEY wrote:
Thanks. Anyone know why it crashes when I try to run it?

You are incrementing i when you mean to increment j.
Oops. Thanks
Sep 30 '06 #7
BWIGLEY wrote:
Thanks. Anyone know why it crashes when I try to run it?
Fixed as far as I could understand it, attached.

Sep 30 '06 #8
"jmcgill" <jm*****@email. arizona.eduwrot e in message
news:OolTg.501$ rS.229@fed1read 05...
BWIGLEY wrote:
Thanks. Anyone know why it crashes when I try to run it?

Fixed as far as I could understand it, attached.
<snip re-formatted code>

Thanks, this is very much appreciated. From now on I think I'll
format my code like this.

I don't know if anyone can be bothered, but if someone could please
tell me how to use random() and floor() ( what to #include etc.) so I
can actually randomly generate a level (I've finished everything else
and it works nicely). I'll probably be able to find this, but they
aren't in the tutorials I've downloaded so far...
Sep 30 '06 #9
BWIGLEY wrote:
>>Thanks. Anyone know why it crashes when I try to run it?
Fixed as far as I could understand it, attached.
<snip re-formatted code>

Thanks, this is very much appreciated. From now on I think I'll
format my code like this.

I don't know if anyone can be bothered, but if someone could please
tell me how to use random()
random() is not standard C.

In standard C you get RAND_MAX which is at least 32767 (but probably is
the maximum int for your system), you get rand() which gives a random
int between [0 and RAND_MAX] inclusive, and a seed function,
void srand(unsigned int seed);

To get a double precision random number, you can do this, no guarantees
about the distribution or anything.

double r;
r=( ((double) rand()) / (double) (RAND_MAX) + (double)(1.0) );

(Personally, I've been using the random number generator from a crypto
library, not the standard function).
and floor()
floor() is in <math.h>
Sep 30 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5479
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
17
18210
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include #include #include #include #include #include #include #include #include #include #include #include
136
5528
by: Merrill & Michele | last post by:
A derangement is a mapping of a set onto itself leaving no element fixed. I realized that that was what I was programming when I was asked to randomly determine who buys presents for whom this year in my wife's family. Obviously, one does not buy for himself. The code is followed by some questions. #include <stdio.h> #include <stdlib.h> #include <time.h>
2
1948
by: MyNameIsnt | last post by:
Can anyone tell me why, when I click on the buttons it register 2 characters on the display? if you use the right mousebutton it works ok, but the buttons dont flash?? it works fine without the aqua buttons, (using just windows forms buttons... Main Form cs file //----------------------------------------------------------------------------------------------------------------------
2
3814
by: Chris Millar | last post by:
Can anyone help me on converting this vb asp page to C#, thanks in advance. chris. <!DOCTYPE HTML PUBLIC "-//W3C//Dtd HTML 4.0 transitional//EN"> <% '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''
0
1897
by: john | last post by:
Hi,All MS Tech Gurus: I need your help!!! It is the second time I post this message, I need get some feedback ASAP, Please Help!! Thanks a lot in advance. John I have a csharp method, using emit to dynamically generate classes & method depends on the meta table in the database,here is my situation 1) In One method I generated the code Dynamic IL Code (Depends on the data pass to it), The generated code works for one dataset but does...
0
5573
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
0
2145
by: Ahmed, Shakir | last post by:
Thanks everyone who tried to help me to parse incoming email from an exchange server: Now, I am getting following error; I am not sure where I am doing wrong. I appreciate any help how to resolve this error and extract emails from an exchange server. First I tried: Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python24\lib\poplib.py", line 96, in __init__ raise socket.error, msg
19
1829
by: fx5900 | last post by:
Hi, i am trying to convert an .osm (openstreetmap) file into gml format and finally to shapefile given this wiki info http://wiki.openstreetmap.org/index.php/GML. I'm using windows and when i entered the following commands osm2gml.py < map_01_data.osm > map_01_data.gml on my dos prompt i get a number of errors, some of which are bellow: Traceback <most recent call last>:
0
10144
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9997
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.