Fahrenheit to Celsius Program [Functions]

Im trying to write a function named celsius that accepts a Fahrenheit temperature as an argument. The function should return the temperature, converted to celsius. Also i have to demonstrate the function by calling it in a loop that displays a table from 0 through 20 and the celsius equivalents. This is what ive got so far.. any help will be appreciate it.


// This program will Accept Fahrenheit as
// an argument and return it as Celsius
// from 0 to 20 using a loop.

#include
#include
using namespace std;

// Function Prototypes
double celsius(double);

int main()
{
// Set Precision

cout << setprecision(12) << fixed << showpoint;

// Make the chart

cout << "Farenheit" << setw(12) << right << "celsius";
cout << "
------------------------------------------
";

// Use The Loop 0 - 20
for (double f = 0; f <= 20; f++)
{
cout << setw(10) << right << f
<< setw(12) << right << celsius(f)
<< endl;
}
return 0;
}


//*************************************
//* Definiton of function celsius *
//* This function accepts fahrenheit *
//* as an agument and returns it as *
//* celsius *
//*************************************


double celsius(double f)
{
double c = (5.0/9.0) * (f - 32);

return c;
}

Comments

  • Everything seems to be correct... so what exactly do you need help with?
  • : Everything seems to be correct... so what exactly do you need help
    : with?

    I actually found the error hehe, in my function i just had to change the variable within the parenthesis.. thanks again..
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion