1 Replies - 5835 Views - Last Post: 09 November 2009 - 09:25 PM Rate Topic: -----

#1 abujamaal  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 10
  • Joined: 17-September 09

Convert Fahrenheit to Celsius - Celsius with + or -

Post icon  Posted 09 November 2009 - 08:56 PM

I need help placing a + or - sign before the celsius number.

/* Write a program that converts integer Farenheit temperatures from 0
   to 212 degrees to floating-point Celsius temperatures with 3 digits
   of precision. Use the formula celsius = 5.0 / 9.0*(fahrenheit - 32) 
   to preform the calculation. The output should be printed in two right-
   justified columns of 10 characters each, and the Celsius temperatures
   should be preceded by a sign of both positive and negative values. */

#include <stdio.h>
#include <stdlib.h>

int main()
{
	double celsius;
	int fahrenheit;

	
	for (fahrenheit = 0; fahrenheit <= 212; fahrenheit = fahrenheit++)
	{
		celsius = 5.0/9.0 *(fahrenheit - 32);
		printf("%10d%10.3f\n", fahrenheit, celsius);
	}		


	if (celsius <= 0 && celsius <= 100)
	{
		printf("%+10.3f", celsius);
	}
	
	
	
	system("pause");
	return 0;
}



Thank you in advance

Is This A Good Question/Topic? 1
  • +

Replies To: Convert Fahrenheit to Celsius - Celsius with + or -

#2 abujamaal  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 10
  • Joined: 17-September 09

Re: Convert Fahrenheit to Celsius - Celsius with + or -

Posted 09 November 2009 - 09:25 PM

I have figured it out. Thanks to those who wanted to help. This is becoming easier as thing are repetative.

/* Exercise 9.13: 9.13.c */
/* Write a program that converts integer Farenheit temperatures from 0
   to 212 degrees to floating-point Celsius temperatures with 3 digits
   of precision. Use the formula celsius = 5.0 / 9.0*(fahrenheit - 32) 
   to preform the calculation. The output should be printed in two right-
   justified columns of 10 characters each, and the Celsius temperatures
   should be preceded by a sign of both positive and negative values. */

#include <stdio.h>
#include <stdlib.h>

int main()
{
	float celsius;
	int fahrenheit;

	
	for (fahrenheit = 0; fahrenheit <= 212; fahrenheit = fahrenheit++)
	{
		celsius = 5.0/9.0 *(fahrenheit - 32);
		printf("%10d%", fahrenheit);

		{
			if (celsius >= 0 && celsius <= 100)
			{
				printf("%+10.3f\n", celsius);
			}
			else if (celsius < 0)
			{
				printf("%10.3f\n", celsius);
			}
		}
	}
		
	
	system("pause");
	return 0;
}


This post has been edited by abujamaal: 09 November 2009 - 09:26 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1