# Temperature conversion...

• 10-20-2005
Onslaught
Temperature conversion...
Hi, I'm new at C programming, and I'm following the HowStuffWorks.com C programming tutorial/guide until I get some books- it has nice examples and lets you experiment. Anyways, I'm working on a temperature conversion program- a basic loop project. I'm trying to convert Fahrenheit to Celcius with user-inputted starting temp, ending temp, and increment value. Problem is, IT KEEPS REPEATING. I've spent an hour trying to figure out why, but i can't find the cause of it all. So here's the code. Thanks

Code:

```#include <stdio.h> int main() { float a, b, c, d;  printf("Enter a value for the starting temperature in Fahrenheit:");   scanf("%f", b);   printf("Enter a value for the ending temperature in Fahrenheit:");   scanf("%f", c);   printf("Enter a value for the temperature increment value in Fahrenheit:");   scanf("%f", d);   a = b;   printf("This is a Fahrenheit to Celcius Conversion Table!");     while (a <= c)     {       if ((a > 98.6) && (a < (a + d)))         {           printf("%f degrees F = %f degrees C\n",               98.6, (98.6 - 32.0) * 5.0 / 9.0);         }         printf("%f degrees F = %f degrees C\n",             a, (a - 32.0) * 5.0 / 9.0);         a = (a + d);     }     return 0; }```
• 10-20-2005
SlyMaelstrom
You had a few minor errors that I fixed, this code works fine for me. You'll just want to format the output on your floats to whatever way you feel nessassary. I set the precision to two places.

Code:

```#include <stdio.h> int main() { float a, b, c, d;  printf("Enter a value for the starting temperature in Fahrenheit:");   scanf("%f", &b);    // You had b, should be &b   printf("Enter a value for the ending temperature in Fahrenheit:");   scanf("%f", &c);    // You had c, should be &c   printf("Enter a value for the temperature increment value in Fahrenheit:");   scanf("%f", &d);    // You had d, should be &d   a = b;   printf("This is a Fahrenheit to Celcius Conversion Table! \n"); // Don't forget your \n here     while (a <= c)     {       if ((a > 98.6) && (a < (a + d)))         {           printf("%.2f degrees F = %.2f degrees C \n",               98.6, (98.6 - 32.0) * 5.0 / 9.0);         }         printf("%.2f degrees F = %.2f degrees C \n",             a, (a - 32.0) * 5.0 / 9.0);         a = (a + d);         }         return 0; }```
Here is the output:
Code:

```Enter a value for the starting temperature in Fahrenheit:52 Enter a value for the ending temperature in Fahrenheit:88 Enter a value for the temperature increment value in Fahrenheit:1 This is a Fahrenheit to Celcius Conversion Table! 52.00 degrees F = 11.11 degrees C 53.00 degrees F = 11.67 degrees C 54.00 degrees F = 12.22 degrees C 55.00 degrees F = 12.78 degrees C 56.00 degrees F = 13.33 degrees C 57.00 degrees F = 13.89 degrees C 58.00 degrees F = 14.44 degrees C 59.00 degrees F = 15.00 degrees C 60.00 degrees F = 15.56 degrees C 61.00 degrees F = 16.11 degrees C 62.00 degrees F = 16.67 degrees C 63.00 degrees F = 17.22 degrees C 64.00 degrees F = 17.78 degrees C 65.00 degrees F = 18.33 degrees C 66.00 degrees F = 18.89 degrees C 67.00 degrees F = 19.44 degrees C 68.00 degrees F = 20.00 degrees C 69.00 degrees F = 20.56 degrees C 70.00 degrees F = 21.11 degrees C 71.00 degrees F = 21.67 degrees C 72.00 degrees F = 22.22 degrees C 73.00 degrees F = 22.78 degrees C 74.00 degrees F = 23.33 degrees C 75.00 degrees F = 23.89 degrees C 76.00 degrees F = 24.44 degrees C 77.00 degrees F = 25.00 degrees C 78.00 degrees F = 25.56 degrees C 79.00 degrees F = 26.11 degrees C 80.00 degrees F = 26.67 degrees C 81.00 degrees F = 27.22 degrees C 82.00 degrees F = 27.78 degrees C 83.00 degrees F = 28.33 degrees C 84.00 degrees F = 28.89 degrees C 85.00 degrees F = 29.44 degrees C 86.00 degrees F = 30.00 degrees C 87.00 degrees F = 30.56 degrees C 88.00 degrees F = 31.11 degrees C```
• 10-21-2005
Onslaught
Thanks a lot. Seemed to overlook the aspersand (sp?)... Works fine now! :D
• 10-21-2005
dwks
ampersand. Sort of like asterisk. :)