Skip to content

Instantly share code, notes, and snippets.

@Elsayegh
Created August 2, 2018 12:46
Show Gist options
  • Select an option

  • Save Elsayegh/4416c5f5017fc5dcd7dec9def78ad41f to your computer and use it in GitHub Desktop.

Select an option

Save Elsayegh/4416c5f5017fc5dcd7dec9def78ad41f to your computer and use it in GitHub Desktop.
C++ Temperature Conversion (C++ Functions)
/*Write a function named celsius that accepts a Fahrenheit temperature as an argument. The function should return the temperature,
converted to Celsius.
Demonstrate the function by calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20
and their Celsius equivalents.
C = 5/9 * (F-32)
*/
#include <iostream>
#include <conio.h>
#include <ctime>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;
float celsius(float f);
int main() {
float c = 0.0f;
cout << "Displaying the celsius temp from 0 : 20" << endl;
for (int i = 0; i < 21; i++) {
c = celsius(i);
cout << i << " Degrees in Fehernheit equal to " << setprecision(2) << fixed << c << " degrees in celsius\n";
}
_getch();
}
float celsius(float f) {
float c;
c = (5.0 / 9) * (f - 32);
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment