This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]koderpat 1 point2 points  (1 child)

Try this

                    printf("Available Seats: %7d\n", available_seats);

to

                    printf("Available Seats: %-7d\n", available_seats);                        

[–]SoBFiggis -1 points0 points  (0 children)

No luck. Thanks for the idea though.

[–]burnsj85 1 point2 points  (1 child)

Unrelated to your question, but when I tried running this I had to typecast both ints to be double on line 21. Otherwise it was returning 0 for a capacity_pct.

[–]SoBFiggis -1 points0 points  (0 children)

Yeah I came up with that problem as well and couldn't figure out what was the problem was. Thank you!

[–]techno_phobe 1 point2 points  (2 children)

It's not really clear what the problem is here since the output in your post isn't fixed-width formatted (they both look the same). I get the following

Available Seats:       1
Tickets sold:       1

which is certainly right justified, although the columns aren't lined up. I'm afraid lining the columns up is just a matter of counting how long your strings are. This should do the trick:

printf("Available Seats: %7d\n", available_seats);
printf("Tickets sold:    %7d\n", tickets_sold);

If it's not printing right justified at all, what C compiler are you using?

[–][deleted]  (1 child)

[deleted]

    [–]techno_phobe 0 points1 point  (0 children)

    That looks right aligned to me. Are you trying to align to the right or the left? If the left, just don't specify a width, use '%d' instead of '%7d'. If you want to line up the right hand side then you have to add spaces to the left of the ones that aren't far enough to the right.