Help with While() loop

This is a discussion on Help with While() loop within the C Programming forums, part of the General Programming Boards category; i am trying to make a conversion table using the while() looping method, and i cant seem to get the ...

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    Question Help with While() loop

    i am trying to make a conversion table using the while() looping method, and i cant seem to get the values to convert properly. any ideas ?
    thanx..


    code
    ______________________________________________
    #include <stdio.h>

    int main(void)

    {
    int inch;
    float mm, meters;
    mm = inch*25.4;
    meters = mm/1000;

    printf("INCHES MM METERS \n ");
    inch = 1;

    while(inch < 11)

    {
    printf("%d %5.2f %5.2f \n",inch,mm,meters);
    ++inch;
    }

    return 0;

    }

  2. #2
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    Also, in this version (better than previous)

    i get an extra space in front of the 1 value, while all others are vertically aligned. (?)

    ___________________________________________
    #include <stdio.h>

    int main(void)

    {
    int inch;
    float mm, meters;
    inch=1;


    printf(" INCHES MM METERS\n ");


    while(inch < 11)

    {
    mm = inch*25.4;
    meters = (mm/1000);
    printf("%4d %10.2f %10.2f \n", inch, mm, meters);
    ++inch;
    }

    return 0;

    }
    its alive... its ALIVE... ITS...AL...IIIVE !!!!!!!!!

  3. #3
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    > printf(" INCHES MM METERS\n ");
    Because there is a space after the '\n' (new line).
    Change this to:
    Code:
    printf(" INCHES MM METERS\n");
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    #include <stdio.h> 
    
    int main ( void ) 
    { 
    	int inch; 
    	float mm, meters; 
    	inch = 1; 
    
    	printf(" INCHES     MM       METERS\n\n"); 
    
    	while ( inch < 11 ) 
    	{ 
    		mm = inch * 25.4; 
    		meters = ( mm/1000 ); 
    		printf("%4d %10.2f %10.2f \n", inch, mm, meters); 
    		inch++; 
    	} 
    	return 0; 
    }
    I made some small changes.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  2. While loop misbehaving (or misunderstanding)
    By mattAU in forum C Programming
    Replies: 2
    Last Post: 08-28-2006, 03:14 AM
  3. loop in a linked linked lists
    By kris.c in forum C Programming
    Replies: 6
    Last Post: 08-26-2006, 01:38 PM
  4. while loop help
    By bliznags in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 12:30 AM
  5. loop issues
    By kristy in forum C Programming
    Replies: 3
    Last Post: 03-05-2005, 09:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21