Created
August 2, 2018 12:46
-
-
Save Elsayegh/4416c5f5017fc5dcd7dec9def78ad41f to your computer and use it in GitHub Desktop.
C++ Temperature Conversion (C++ Functions)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*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