Thread: Add Header To Column

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

    Add Header To Column

    Hi all!

    Brand new to C Programming. I'm working on a little sample program presented at 'Howstuffworks.com' - the c programming section, and I have to add a header to a table as one of the challenges. I've tried everything I can think of but no go, including searching the forums here. I did find a few tips but I suspect the problem is that I'm not inserting the code correctly. Below is the simple little program. It converts degrees to celsius. What I want to do is put a header at the top of the table/column. Where would that go in the code? I'm thinking it's an extra printf line above the one that prints the column, but nothing I'm trying is outputting correctly. Many thanks in advance!

    Code:
    #include <stdio.h>
    
    int main()
    {
        int a;
        a = 0;
        while (a <= 100)
        {
            
    	printf("%4d degrees F = %4d degrees C\n",
                a, (a - 32) * 5 / 9);
            a = a + 10;
        }
        return 0;
    }

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You have a while loop that prints the conversions between 0 and 100. The loop starts at the { after the while and ends at the corresponding } before return 0;

    If you want something to just print once, you don't want to put it inside the loop, right? So put it before the while statement.

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    Many thanks!

    Works great!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class methods in header or source file?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2007, 05:23 AM
  2. header file/class problems
    By Calef13 in forum C++ Programming
    Replies: 6
    Last Post: 07-20-2007, 08:33 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Where can i add a header file other than include directory
    By asdfasdfasdf in forum C++ Programming
    Replies: 4
    Last Post: 09-26-2002, 07:23 AM
  5. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM