2 Replies - 198 Views - Last Post: 01 February 2013 - 12:32 AM Rate Topic: -----

#1 Bawnawgwa  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 21-January 13

What is wrong with my local header to make it not work?

Posted 01 February 2013 - 12:19 AM

#include <stdio.h>
#include <math.h>
#include <conio.h>
#include "Celsius.h"

int main()
{
	float x;

	printf("Enter the degrees Fahrenheit you wish to convert to Celsius: ");
	scanf("%f", &x);

	Celsius(x);

	getch();
	return(0);
}

And here is Celsius.h code:
#include <stdio.h>


void Celsius(float F)
{
	float C;
	
	C = ((F - 32) * (5 / 9));

	printf("%.2f degrees Fahrenheit is the same as %.2f degrees Celsius!\n", F, C);
	
}


I am stumped. I don't see what is wrong nor can the internet tell me what is wrong with this. It tells me:
"(correct number) degrees Fahrenheit is the same as -0.00 degrees Celsius." Celsius is ALWAYS -0.00 degrees... haha I just don't see the error here... I feel so close and it is probably something silly... or maybe I did something completely wrong? I don't know...

Is This A Good Question/Topic? 0
  • +

Replies To: What is wrong with my local header to make it not work?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2089
  • View blog
  • Posts: 3,179
  • Joined: 21-June 11

Re: What is wrong with my local header to make it not work?

Posted 01 February 2013 - 12:25 AM

5/9 is an integer division because both operands (5 and 9) are integers. So the result is 0 and you're multiplying F-32 by 0, resulting in 0. Use 5.0/9.0 instead to use floating point division.

PS: A header file should not contain function definitions. This will lead to linker errors if you include the header file into multiple C files. It should only contain the function declaration. The definition should be in its own C file.
Was This Post Helpful? 0
  • +
  • -

#3 Bawnawgwa  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 21-January 13

Re: What is wrong with my local header to make it not work?

Posted 01 February 2013 - 12:32 AM

Lol thank you! I got it to work now. Such a silly mistake. I gotta watch those floats...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1