Hi, I don't understand the portions I put in bold in this function for converting Fahrenheit to Celsius. The texts are "FtoC." I am guessing "FtoC" is a variable; I really am confused about why "to" is in there. What does the paranthesis (float f) indicate?

#include <stdio.h>

float [B]FtoC[/B](float f)
{
  float c;
  c = (5.0 / 9.0) * (f - 32.0);
  return c;
}

int main(void)
{
  float fahr, celsius;
  int lower, upper, step;

  lower = 0;
  upper = 300;
  step = 20;

  printf("F     C\n\n");
  fahr = lower;
  while(fahr <= upper)
  {
    celsius = FtoC(fahr);
    printf("%3.0f %6.1f\n", fahr, celsius);
    fahr = fahr + step;
  }
  return 0;
}

Recommended Answers

All 2 Replies

here FtoC is a function.

Now what is function?

A function is a small set of instructions designed to operate on its given input (aka parameters or arguments) and perform some action or return some output. Generally in programming a commonly used strategy is to take a large program and break it into smaller chunks, which are turned into functions.

float FtoC means the return type of this function is float.
i would suggest to stick with the book or the course you're following. eventually you come to know what is function.

check this for a quick look.

>I am guessing "FtoC" is a variable
It's a function.

>I really am confused about why "to" is in there.
That's part of the function name. It implies "Fahrenheit to Celsius".

>What does the paranthesis (float f) indicate?
The function takes one argument of type float.

A function is a small set of instructions designed to operate on its given input (aka parameters or arguments) and perform some action or return some output.

Meh. It's not wrong, but I don't think it's all that enlightening either. But it's also hard to describe the concept in a single sentence. I like this one:

1) A function is a named block of code:

/* The name */
hello()
/* The block of code */
{
  printf ( "Hello, world!\n" );
}

2) A function can be "called" multiple times without rewriting the block

hello(); /* Prints "Hello, world!" */
hello(); /* Prints "Hello, world!" */
hello(); /* Prints "Hello, world!" */

3) A function can accept placeholders (called parameters) which the caller can use to customize the behavior of a function for each call:

add ( int a, int b )
{
  printf ( "%d + %d = %d\n", a, b, a + b );
}
add ( 2, 2 ); /* Prints "2 + 2 = 4" */
add ( 5, 3 ); /* Prints "5 + 3 = 8" */
add ( 10, 20 ); /* Prints "10 + 20 = 30" */

4) A function can produce a result and pass it back to the caller:

int add ( int a, int b )
{
  return a + b;
}
printf ( "2 + 2 = %d\n", add ( 2, 2 ) ); /* Prints "2 + 2 = 4" */
printf ( "5 + 3 = %d\n", add ( 5, 3 ) ); /* Prints "5 + 3 = 8" */
printf ( "10 + 20 = %d\n", add ( 10, 20 ) ); /* Prints "10 + 20 = 30" */

Beyond that it's just details.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.