Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 12-12-2004, 12:34 PM   #1 (permalink)
Junkie
 
zero2's Avatar
 
[C]Celsius & Farenheit Conversion Table

I kind of have this one worked out, somewhat. What I'm trying to do, is create a table using a for loop. The table will have Celsius from 0 to 100 and a table for Farenheit 32 to 212.

Here's what I got:

Code:
/* This program prints out a conversion table for Celsuis to Farenheit (0 to 100) and Farenheit to Celsius (32 to 212).
Written by:

*/

#include <stdio.h>

#define Conversion_Factor (100.0 / 180.0)

int main (void)
{
/* Local Definitions */
	float x;
	float y;
    
/* Statements */
printf(" Farenheit Conversion Table\n");
for ( x = 0; x <= 100; x++)
{
/* Centigrade to Farenheit */
printf("%.2f\t", (Conversion_Factor * x) + 32);
}
printf("\n");

return 0;
}
/* main */

/* Results */
The results I get are the following, which is almost right except my ending value doesn't quite make it to 212, for some odd reason.

Code:
 Farenheit Conversion Table
32.00   32.56   33.11   33.67   34.22   34.78   35.33   35.89   36.44   37.00
37.56   38.11   38.67   39.22   39.78   40.33   40.89   41.44   42.00   42.56
43.11   43.67   44.22   44.78   45.33   45.89   46.44   47.00   47.56   48.11
48.67   49.22   49.78   50.33   50.89   51.44   52.00   52.56   53.11   53.67
54.22   54.78   55.33   55.89   56.44   57.00   57.56   58.11   58.67   59.22
59.78   60.33   60.89   61.44   62.00   62.56   63.11   63.67   64.22   64.78
65.33   65.89   66.44   67.00   67.56   68.11   68.67   69.22   69.78   70.33
70.89   71.44   72.00   72.56   73.11   73.67   74.22   74.78   75.33   75.89
76.44   77.00   77.56   78.11   78.67   79.22   79.78   80.33   80.89   81.44
82.00   82.56   83.11   83.67   84.22   84.78   85.33   85.89   86.44   87.00
87.56
Press any key to continue
As for the other way around Farenheit to Centigrade, I have coded it the following way, but when I added it to the end of the previous code, it stops and doesn't execute.

Code:
printf("Centigrade Conversion Table\n");
for( y = 32; y <= 212; y++)
{
/* Farenheit to Centigrade */
printf("%.2f\t", Conversion_Factor * (y - 32);
}
printf("\n");
TIA, for any help or suggestions that you can provide.
zero2 is offline  
Old 12-12-2004, 02:11 PM   #2 (permalink)
I am Winter Born
 
Pragma's Avatar
 
Location: Alexandria, VA
Code:
#include <stdio.h>
#define CFRATIO (9.0/5.0)
#define FCRATIO (5.0/9.0)

int main (void)
{
/* Local Definitions */
  int i;  
        
  /* Statements */
  printf("Celcius -> Farenheit Conversion Table\n");
  for ( i = 0; i <= 100; i++) {
    /* Centigrade to Fahrenheit */
    printf("%.2f\t", (CFRATIO * i) + 32);
    if( ( (i+1) % 10 ) == 0 ) {
      printf("\n");
    }
  }
  printf("\nFahrenheit -> Celcius Conversion Table\n" );
  for ( i = 32; i <= 212; i++) {
    /* Fahrenheit to Centigrade */
    printf("%.2f\t", (i - 32) * FCRATIO );
    if( ( (i+1) % 10 ) == 0 ) {
      printf("\n");
    }
  }
  printf("\n");
  return 0;
}
Cleaned up your code a bit and fixed a few bugs.
Pragma is offline  
Old 12-12-2004, 04:19 PM   #3 (permalink)
Junkie
 
zero2's Avatar
 
I just ran it and it works .

The only thing that I don't understand is this statement, if( ( (i+1) % 10 ) == 0 )? Can you tell me what this does?

Thanks again for your help

--zero2
zero2 is offline  
Old 12-12-2004, 04:57 PM   #4 (permalink)
Insane
 
Location: Wales, UK, Europe, Earth, Milky Way, Universe
It means "if (i + 1) is a multiple of ten..."
__________________
There are only two industries that refer to their customers as "users". - Edward Tufte
welshbyte is offline  
Old 12-12-2004, 05:23 PM   #5 (permalink)
I am Winter Born
 
Pragma's Avatar
 
Location: Alexandria, VA
It's just to make printing the output appear in nice columns of 10. Nothing too important, look up the modulus operation.
Pragma is offline  
Old 12-12-2004, 05:56 PM   #6 (permalink)
Junkie
 
zero2's Avatar
 
Oh now I see it, ok.
zero2 is offline  
 

Tags
ccelsius, conversion, farenheit, table


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:55 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73