Thread: Output in columns

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    2

    Output in columns

    I have a program that computes basically a bouncy ball inside a fixed area, and if it has direct collision with stationary object it prints the collision info in a file... I have all the logic done but i want to get it to write the information in colums:

    Number of moves to generate=100
    Moving Object: x=1 y=8 x_movement=-1 y_movement=1
    Stationary Object: x=1 y=10

    Collision:1 Move:2 Location:2,5 Direction:5,2
    Collision:2 Move:58 Location:4,2 Direction:2,3

    A total of 2 collisions occurred in 100 moves.


    However i keep getting my first row, pushed over like this :

    Collision:1 Move:2 Location:2,5 Direction:5,2
    Collision:2 Move:58 Location:4,2 Direction:2,3


    How can i fix it ? Im using the setw(x) and it should work??

    Code:
    if ((nextx==statx)&&(nexty==staty)){	// Direct collision
    				
    					collisions++;
    					
    					string loc, dir;
    					loc= currentx + "," + currenty;
    					dir= movx + "," + movy;
    					
    					output << left;
    					output  << setw(10) << "Collision:" << setw(10) << collisions   
    					   << "Move:"  << setw(10) << step << "Location:" << setw(10) << loc
    					   <<  "Direction:" << setw(10) << dir << endl;
    					   
    					movx=-movx;
    					movy=-movy;
    					
    					nextx=currentx+movx;
    					nexty=currenty+movy;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Try using 'setprecision( number )' for your numbers.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Formatting output into aligned columns
    By Kheila in forum C++ Programming
    Replies: 8
    Last Post: 11-14-2005, 09:47 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM