Thread: Simple program i cant get (dot moving)

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    Simple program i cant get (dot moving)

    i need to have a program with a for loop that has a dot moving up and down and one going right and left. and it needs to like delete the dot after if goes past it...get it? so its a single dot moving right and left and a single dot moving up and down. also this is in C++ so...yea


    anyone help?

    -Lupusk

    here is my code so far it only moves the one dot downward and the right dot only half way accross

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <dos.h>
    
    
    int main()
    {
    
    	clrscr();
    	int x, y, xx, yy;
    
    
    	for (y = 0; y <= 49; y++)
    	{
    
    
    	x = y * 1.5;
    	gotoxy(1,y);
    	cout << "*" << endl;
    
    	gotoxy(x,1);
    	cout << "*";
    
    	delay(10);
    	}
    
    
    	getch();
    	return 0;
    }

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    x = y * 1.5;

    y is declared as int which doesnt support floating point values.

    But I can help you more if I can understand what your trying to do. Try explaining it again.

    [note]
    Also you should use standard headers
    What is C++?

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    As for deleting each old dot, call clrscr() at the beginning of each loop iteration. Judging from your call to delay(), time efficiency is not a top priority.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    2
    i dont know what standard headers are....thats what i learned with and being taught right now so i dunno but umm the clrscr thing i cant do ...i need it to have a gotoxy clearer .....


    i want 2 dots moving up and down and the ohter moving right and left at the same exact time...so in one for statement one dot needs to go down and one dot needs to go alllll the way right and the other for statement.....the opposite


    ^
    |
    ^
    |
    |
    ^
    |
    ^
    \/
    |
    |
    \/
    |
    |
    |
    |----<-----<---------<---------------->-------->------->




    like that the dots go baaaack and foooorth for ever

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    well the concept is like this.

    Code:
    int x, y;
    bool dir;
    
    // loop forever
    for ( ;; ) {
    
        clrscr ();   // Inside loop or else the dots will leave foot prints.
    
        if ( x == 20 ) dir = false;
        if ( x == 0 ) dir = true;
    
        if ( dir ) {
     
            x++;
            y--;'
    
        }
    
        else {
    
            x--;
            y++;
    
        }
    
        gotoxy ( x, 20 ); // Im not sure where on the y axis you want it
        cout << "*";
    
        goto ( 1, y );
        cout << "*"; 
    
    }
    Its something like that....
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  2. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  3. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. I need help on a formula for this simple program.
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-28-2002, 10:01 PM