Thread: Question about indention

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    9

    Question about indention

    Hello everybody,

    I'm new here and also pretty new to the C-language.

    Here is the Problem:

    I have several floats and I need to print them out, but they should be in one line at the end. But C always prints them with the first number on the same level, so if the numbers are not the same length it doesn't look good. What I need to do is to make the end "levelled".



    how can i do that?

    thanks a lot

    liricas

  2. #2

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    9
    hmm i'm sorry but i still can't figure it out (even with the help of wikipedia)

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Use the field width specifier:

    printf("%FieldWidthSpecifierNumberf", somefloat);

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Perhaps you should use something like this

    Code:
    printf("%.5f", num);
    This would limt the decimal points up to 5 placs.

    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    9
    Code:
    The total number of books ordered: 6
    The average movie price: $ 595.50
    The minimum movie price: $ 45.99
    The maximum movie price: $ 2345.77
    This is the output I get.

    But the output should look like this

    Code:
    The total number of books ordered: 3
    The average movie price: $ 13.45
    The minium movie price:  $  6.55
    The maximum movie price: $ 15.95
    the end should be nicely leveled....

    how can i achieve that?

    thx for your help
    Last edited by liricas; 04-16-2009 at 05:25 PM.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what is your code to print that?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Apr 2009
    Posts
    9
    Code:
       printf("The total number of movies ordered: %.0f\n",numbooks);
       printf("The average movie price:\t$ %.2f\n",average);
       printf("The minimum movie price:\t$ %.2f\n",lowest);
       printf("The maximum movie price:\t$ %.2f\n\n",highest);
    this is the code

    thx for any help

  9. #9
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    May be this

    Code:
     printf("The average movie price:\t$ %5.2f\n",average);
     printf("The minimum movie price:\t$ %5.2f\n",lowest);
     printf("The maximum movie price:\t$ %5.2f\n\n",highest);
    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  10. #10
    Registered User
    Join Date
    Apr 2009
    Posts
    9
    Quote Originally Posted by ssharish2005 View Post
    May be this

    Code:
     printf("The average movie price:\t$ %5.2f\n",average);
     printf("The minimum movie price:\t$ %5.2f\n",lowest);
     printf("The maximum movie price:\t$ %5.2f\n\n",highest);
    -ssharish
    worked out perfectly!


    thank you soo much

    liricas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM