?
Solved

Simple C Program

Posted on 2000-03-22
4
Medium Priority
?
191 Views
Last Modified: 2010-04-15
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
Comment
Question by:lhutton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 2647661
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
 

Accepted Solution

by:
jpjpjp earned 200 total points
ID: 2647684
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
 

Author Comment

by:lhutton
ID: 2647686
I need celsius to increase by 5, so I get a table like:

Celsius | Fahrenheit
======|=========
    0       |     32
    5       |     ..
   10      |     ..
  100     |    212
0
 

Author Comment

by:lhutton
ID: 2647699
Perfect! Thanks :) My confusion was with using i instead of C.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question