#include <iostream>
#include <iomanip>
using namespace std;

void celsius(int);

int main()
{
	cout <<	setprecision(2) << fixed << showpoint;
	cout << "This program displays a table of the Fahrenheit temperatures" 
	<< "\n0 thorugh 20 and their celsius equivalents.\n";

	celsius(0);

return 0;
}

void celsius(int fahr)
{	double cels;
	
	cout << "Fahrenheit \t \t Celsius\n";
	
	for (fahr; fahr <= 20; fahr++)
	{	cels = (5.0 / 9.0 )*(fahr - 32);
	cout << fahr << "\t" << "\t"<< "\t " << cels << endl; 
	}


}

The question is
"Write a function named celsius that accepts a Fahrenheir temperature as an argument. The function should return the temperature, converted to celsius. Demonstrate the function by calling a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their celsius equivelents."

It sounds like to me that I just need the function to form the celsius degree, and that it should be displayed in the main function and not the void function like I have it above.

Recommended Answers

All 2 Replies

I would first write your function like this :
double celcius(double fahrenheit)
{
//do calculation
return result
}

Now use the function in a for loop to make your table.

Easy, just change your function to

double celsius (int fahr)
{ return (5.0 / 9.0)*(fahr - 32); }

And put the call for that inside the for loop you used.

// Top of table
for (int fahr = 0; fahr <= 20; fahr++)
{ double cels = celsius (fahr); 
   /* Display individual data for table */}
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.