mirror of
https://github.com/JustKato/Tempera.git
synced 2026-03-09 11:49:46 +02:00
+
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
temp
|
||||
tempera
|
||||
22
README.md
Normal file
22
README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# About
|
||||
This is a simple program that can convert temperature from fahrenheit to celsius and vice-versa, the usage is explained bellow and pretty straight-forward.
|
||||
|
||||
The program should be quite light-weighted and easy to use in bigger systems, I personally created it because I Found a need for a program that quickly calculates this for me through CLI for implementation with different scripts and automations, also I found that `C++` is quite a bit faster and much better optimized in doing this than `php`
|
||||
|
||||
# Compilation
|
||||
To compile the program it's quite straight forward on linux, simply run the `compile.sh` file, which requires the `g++` package, to install it on Debian based systems simply run `sudo apt install g++`.
|
||||
|
||||
# Usage
|
||||
The package was created expecting pipe-in stdin, you can pipe input straight into it or you can simply run it and type numbers in, simplest usages is: `echo 64 | ./tempera` which will return `17.7778`, you can add this to your `/usr/bin` folder or `/bin` fir ease of use, or simply add it to your path.
|
||||
|
||||
If you wish to convert `Celsius` to `Fahrenheit` simply add in another argument to the program, so when you type `echo 16 | ./tempera 1` it will return `60.8`
|
||||
|
||||
# Examples
|
||||
```bash
|
||||
# 🌡 Fahrenheit -> Celsius
|
||||
echo 64 | ./tempera # Returns 17.7778
|
||||
|
||||
# 🌡 Celsius -> Fahrenheit
|
||||
echo 16 | ./tempera 1 # returns 60.8
|
||||
|
||||
```
|
||||
1
compile.sh
Normal file
1
compile.sh
Normal file
@@ -0,0 +1 @@
|
||||
g++ -o3 main.cpp -o tempera
|
||||
31
main.cpp
Normal file
31
main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
double ftc(double fahrenheit) {
|
||||
return ( fahrenheit - 32.0 ) * 5.0 / 9.0;
|
||||
}
|
||||
|
||||
double ctf(double celsius) {
|
||||
return ( celsius * 9.0 / 5.0 ) + 32;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
double inp = 0.0;
|
||||
|
||||
// Read input from pipe in
|
||||
std::cin >> inp;
|
||||
|
||||
// If an argument is passed, then do the reverse ( c -> f instead of f -> c)
|
||||
if ( argc > 1 ) {
|
||||
// Cout the temperature in celsius
|
||||
cout << ctf(inp) << "\n";
|
||||
} else {
|
||||
// Cout the temperature in celsius
|
||||
cout << ftc(inp) << "\n";
|
||||
}
|
||||
|
||||
// Return success to stdout
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user