Thread: Printf Alignment

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    1

    Printf Alignment

    I am having a little issue here. How can i get these two printf statements to align?


    //print the total calculations
    printf("\nName\t\t Clock#\t Wage\t Hours\t OT\t Gross\n");
    printf("Totals:\t %.1f\t %.1f\t $%.2f\n", hourstotal, overtimetotal, grosstotal);

    im trying to get hourstotal, overtimetotal, and grosstotal align under wage, hours, gross. The problem is they are way out of place. How exactly can i get these to align?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You could try using the tab character prior to printing the totals.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    This tells you how to do things such as make sure that each thing printed is a certain width:
    printf - C++ Reference

    Have a go using what it talks about, and post your attempt with that if you can't quite get it.
    Note that you wont need to use any tab characters in your heading, or elsewhere.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf alignment
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 04-10-2009, 11:48 AM
  2. set() alignment
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 03-14-2002, 04:20 AM
  3. help with alignment
    By bigb1999 in forum C++ Programming
    Replies: 1
    Last Post: 02-04-2002, 06:22 PM
  4. Need help with alignment
    By cazil in forum C++ Programming
    Replies: 2
    Last Post: 01-27-2002, 12:27 PM
  5. trouble with printf alignment
    By hyaline in forum C Programming
    Replies: 5
    Last Post: 09-22-2001, 01:39 AM