I finally broke down and wrote my first header file, but one of my functions is acting a little weird... This function is supposed to convert from Celsius to Fahrenheit but whenever I call the function, it returns an incorrect value. Is there an easy way to multiply the float by 9/5?

float ctof(float temp)
{
      float fahrenheit = temp;
      fahrenheit = (9/5)*fahrenheit + 32;
      return fahrenheit;
}

you don't normally put executable code in a header file. All header files contain are function prototypes, classes , structures and macros. Everything else goes in the *.c or *.cpp implementation file.

>> (9/5)*fahrenheit + 32
that is the same as 1 * fahrenheit + 32 because 9/5 = 1 (integer arithmetic discards all fractions)

Thanks I guess I'll have to research more before I proceed.

Start with this thread. Note that it is using floating point arithmetic, not integer arithmetic like you tried to do.

Thanks! I got it to work now so I can continue with my project!

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.