Results 1 to 6 of 6

Thread: not plotting correctly...

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    why don't these plot correctly? in bold is the important code:
    Code:
    /*---=== C++ BALL MOVER===---
    ---===STEVE MACK===---*/
    
    #include <iostream.h> //our normal i/o header
    
    int dummy; //so the console doesn't close too early
    int Y; //THE Y AXIS IN THE MATRIX
    int X; //THE X AXIS IN THE MATRIX
    int ballY; //The ball's Y value
    int ballX; //The ball's X value
    int mainLoop; //Used to call the code so many times
    
    int plotBall(int PlotX, int PlotY); //plot function prototype
    int clearScreen();  //clearScreen function prototype
    
    int main() //the main function
    {
    	cout<<"|||---===Welcome to BALL MOVER v0.1===---|||"<<endl; // Title stuff
    	cout<<"BALL MOVER was written by Steve Mack"<<endl; // author info
    	
    	ballY=1; //  }  These 2 vars will hold the balls position
    	ballX=1; //  }
    	
    	for(mainLoop=1; mainLoop<6; mainLoop++){
    		clearScreen(); //this will clear our screen
    		plotBall(ballX,ballY);
    		ballX=ballX++;
    		ballY=ballY++;
    	}
    	
    	cout<<endl<<"Enter Anything To Quit: "; //  }  This is the ending sequence
    	cin>>dummy;//                               }  "Press any key to exit", KEYPRESSED, close;
    	return 0; //                                }
    }
    
    
    //================*************FUNCTIONS*************=====================
    
    int plotBall(int PlotX, int PlotY){ //this function plots the ball
    	//THE MAIN MATRIX
    	int FinalDrawVar;
    
    	for(X=1; X<82; X++){ //Goes through the X axis
    		if(PlotX==X){
    			for(Y=1; Y<11; Y++){
    				cout<<endl; //next line
    				if(PlotY==Y){
    					for(FinalDrawVar=1; FinalDrawVar<(X--);FinalDrawVar++){
    						cout<<"*"; //draw the spaces
    					}//End FinalDrawVar loop
    					cout<<"O"; //draw the ball
    					X=NULL;
    					Y=NULL;
    					return 0;
    				}
    
    			}//end Y Loop
    		} //ends drawing the ball
    	} //end X axis cycle
    	return 0;
    }
    
    int clearScreen(){ // This function will clear the screen.
    	//couts 5041 spaces to clear the screen
    	int clearScreenCounter;
    	for(clearScreenCounter=1; clearScreenCounter<11; clearScreenCounter++){ //endl does what we need
    		cout<<endl;
    	}
    	return 0;
    }

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    I think your problem is in this code:
    Code:
    for(FinalDrawVar=1; FinalDrawVar<(X--);FinalDrawVar++){
    						cout<<"*"; //draw the spaces
    					}//End FinalDrawVar loop
    X-- is a statement. It decrements (takes one away from) X. Every time the for loop finishes, it checks if the expression ( FinalDrawVar<(X--) ) evaluates to true, and if it does it repeats the loop. Every time this expression is evaluated, it decrements X.

    So all you have to do is change X-- to X-1, and it should work.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Oh yes, by the way, it's a bit pointless writing BallX = BallX++. You may as well just write BallX++.

    ++X is preincrement
    --X is predecrement
    X++ is postincrement
    C++ is postdecrement

    The difference between pre and post is that ++X evaluates to X+1 as an expression, and X++ evaluates to X as an expression. Both act the same as a statement though - basically they represent X=X+1.
    Harry.

    "From one thing, know ten thousand things."

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    But 'X' is cycling though my box...keeping it at 1 only checks the first column...I probably should have stated the problem better If I have it plot at 6,1 and loop it 4 times, it comes out something like
    First time: 5.1
    Second Time: 5,1
    Third Time: 6,1
    Fourth Time: 6,1
    Fifth Time 7,1


  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Right.... and what is it doing at the moment?
    Harry.

    "From one thing, know ten thousand things."

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I put the carot(^) in so I could count spaces before the "O" is drawn, but it doesn't count the amount of spaces I specify.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width