Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/source/cprogramming/Ex_1.15_tempconv.rst
1241 views
=========================================================
Exercise 1.15 - Temperature Convertor using function call
=========================================================

Question
--------


Rewrite the temperature conversion program of Section 1.2 to use a function for
conversion.

Solution
--------

.. literalinclude:: ../../languages/cprogs/Ex_1.15_tempconv.c
   :language: c
   :tab-width: 2

.. runcode:: ../../languages/cprogs/Ex_1.15_tempconv.c
   :language: c
   :codesite: ideone

Explanation
===========


In this program we are going to convert a given Fahrenheit temperature to
Celsius or Celsius temperature to Fahrenheit temperature using the formula
C=(5/9)(F-32 ).  We retain most of the program from section 1.4.  In addition
This program contains functions such as fahrtocelsius and celsiustofhar. The
functions fahrtocelsius and celsiustofhar are used to make the program more
dynamic by giving choices to the users for conversion between 1 - Fahrenheit to
Celsius Conversion 2 - Celsius to Fahrenheit Converion.



.. seealso::

   * :c-suggest-improve:`Ex_1.15_tempconv.c`
   * :c-better-explain:`Ex_1.15_tempconv.rst`