Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*we does the F to C conversions, gunna add the C back to F as well.
- mathew myers
- i know this "could" have been simpler but i gotta "challenge" myself a little bit so i went for a little bit more functionality*/
- #include<iostream>
- #include<string>
- double converter(bool b, double t);
- void main()
- {
- using namespace std;//declairations
- double t = 0;
- string s = "";
- cout << "Please enter f if you want to use the Fahrenheit to Celcius converter, to use the Celcius to Fahrenheit converter just press enter.\n";
- cin >> s;
- if( s == "f")//yay you get to choose between converters
- {
- cout << "Please enter the temperature in Fahrenheit.\n";
- cin >> t;
- cout << "The temperature in Celcius is: " <<converter(true,t) << "\n";
- }
- else
- {
- cout << "Please enter the temperature in Celcius.\n";
- cin >> t;
- cout << "The temperature in Fahrenheit is: " <<converter(false,t) << "\n";
- }
- }
- /*the formula used/
- °C x 9/5 + 32 = °F
- (°F - 32) x 5/9 = °C */
- double converter(bool b, double t)
- {
- if ( b == true) //true means the F to C and false means C to F
- {
- return ((t - 32) * 5.0/9.0); //might as well save lines of code and space and just have the entire calculation on the return.
- }
- else
- {
- return (t * 9.0/5.0 + 32);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment