General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 20th, 2003, 06:58 PM
Chuebacca Chuebacca is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 Chuebacca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Passing Boolean error?

Hey, im a c++ dabbler, and i tried to write a simple program where a '*' bounced off of the boundaries (0 and 70) of a single dimensional array. Im not sure where, or what the error is. If anyone can help me out id really appreciate it, the code is in the attached txt file.
Attached Files
File Type: txt bouncing.txt (881 Bytes, 289 views)

Reply With Quote
  #2  
Old March 23rd, 2003, 01:53 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Are you getting any compile/runtime errors, or are you just not receiving the results you're after?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old March 23rd, 2003, 06:59 PM
Chuebacca Chuebacca is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 Chuebacca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
No Errors and no Warnings. All that happens is the object that is suppose to ricochet of the boundaries simply hits the boundary wall then dissappears.

Reply With Quote
  #4  
Old May 27th, 2003, 08:15 AM
Nautilus Nautilus is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Newcastle, UK
Posts: 6 Nautilus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Nautilus
not sure if you got this fixed yet, but try this code.
Code:
#include<iostream.h>

void main(void)
{
	char array[70];
	int x = 0;
	int filler;
	bool move = true;
	bool movement(int x, bool move);
	void showarray(char array[70]);
	int rotations = 0;

	/* fill array with 70 #'s */
	do
	{
		array[x] = '#';
		x++;
	}while(x<=70);
	
	/* put '*' into arrays first position */
	x = 0;
	array[x] = '*';
	/* print the array as it is now */
	showarray(array);

	/* for 500 rotations move the '*' in the array */
	do
	{
		/* check direction - first time in, x = 0, so forward motion */
		movement(x, move);
		/* while moving forwards alter the array */
		while(move == true)
		{	
			filler = x;
			x++;
			array[x] = '*';
			array[filler] = '#';
			/* show the new array */
			showarray(array);
			/* check direction again - if false,
			   jumps out of this loop into the next */
			movement(x, move);
		}

		while(move == false)
		{
			filler = x;
			x--;
			array[x] = '*';
			array[filler] = '#';
			showarray(array);
			movement(x, move);
		}

		rotations++;

	}while(rotations<500);

}

/* control the movement (direction) of the '*' in the array */
bool movement(int x, bool move)
{
	if(x==0)
		move = true;
	if(x==70)
		move = false;
	return(move);
}

/* print the current array */
void showarray(char array[])
{
	int x = 0;
	do
	{
		cout<<array[x];
		x++;
	}while(x<=70);
	cout<<endl;
}

basically it removes the if-else statement you had and replaces it with 2 while loops that continually check the movement function for the direction.

This hasnt been tested, but it looks as though it should work.By the way, its always a good idea to comment your code so others know straight away what piece of code does what instead of trying to work it out.

if it doesnt work when compiled try using the statement

Code:
move = movement(x, move)

to change the value of move, as the movement function may not be altering the move variable properly

Hope this helped

Reply With Quote
  #5  
Old May 27th, 2003, 09:23 PM
Chuebacca Chuebacca is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 2 Chuebacca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It Worked!

Hey, thanks a lot man! When I used your code as displayed it did the same exact thing that it did before. However when I replaced the "movement(x, move)" with "move = movement(x, move)" it worked perfectly. Thanks for your help and i'll comment my programs from now on.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Passing Boolean error?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway