• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

Simple C Program

I'm trying to write a program to print a conversion table from 0 to 100 celsius (in intervals of 5) to fahrenheit in this format. I have the following but can't get the intervals to increase by 5.

#include <stdio.h>

int main(void)
{
  float C=0,F;
  int i;
  printf("Celsius | Fahrenheit\n");
  printf("========|===========\n");
  for (i=0; i<=100; i=i+5)
  {
    F=9*C/5+32;
    printf("%5.0f   |%7.0f    \n",C,F);
    C=5;
  }
  return 0;
}
0
lhutton
Asked:
lhutton
  • 2
1 Solution
 
ozoCommented:
You've got i to increase by 5, do you want to do anything with i?
What do you want to increase by 5?
0
 
jpjpjpCommented:
the variable C will always be assigned to 5 (in the for loop, u put C=5).

You can try this:

int main (void)
{
   float C,F;

   printf ("Cel   Fara\n");

   for (C=0.0; C < 100.0; C+=5.0)
   {
      F = 9.0*C/5.0 + 32.0;
      printf ("%5.0f | %7.0f \n",C,F);
   }
   return 0;
}
note that you are allowed to use float as the for loop directive.
0
 
lhuttonAuthor Commented:
I need celsius to increase by 5, so I get a table like:

Celsius | Fahrenheit
======|=========
    0       |     32
    5       |     ..
   10      |     ..
  100     |    212
0
 
lhuttonAuthor Commented:
Perfect! Thanks :) My confusion was with using i instead of C.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now