Advertisement
KingYC

C++ code used for Stack Overflow qeustoin

Aug 2nd, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void CtoF() {// c to f furmula
  6.     double input;
  7.     cout << "Enter a number[Celsius-Fahrenheit]" << endl;
  8.     cin >> input;
  9.     cout << "it's " << input * 1.8 + 32 << " Fahrenheit " << endl;
  10.     return;
  11. }
  12. void CtoK() {// c to k  furmula
  13.     double input;
  14.     cout << "Enter a number[Celsius-Kelvin]" << endl;
  15.     cin >> input;
  16.     cout << "it's " << input + 273.15   << " Kelvin " << endl;
  17.     return;
  18. }
  19. void FtoC() {//f to c furmula
  20.     double input;
  21.     cout << "Enter a number[Fahrenheit-Celsius]" << endl;
  22.     cin >> input;
  23.     cout << "it's " << input / 1.8 - 32 << " Celsius " << endl;
  24.    
  25. }
  26. void FtoK() {//f to k furmula
  27.     double input;
  28.     cout << "Enter a number[Fahrenheit-Kelvin]" << endl;
  29.     cin >> input;
  30.     cout << "it's " << input / 1.8 - 32 + 273.15 << " Kelvin " << endl;
  31.     return;
  32. }
  33. void KtoF() {// k to f furmula
  34.     double input;
  35.     cout << "Enter a number[Kelvin-Fahrenheit]" << endl;
  36.     cin >> input;
  37.     cout << "it's " << (input - 273.15) * 1.8 + 32 << " Fahrenheit " << endl;
  38.    
  39. }
  40. void KtoC() {// k to c furmula
  41.     double input;
  42.     cout << "Enter a number[Kelvin-Celsius]" << endl;
  43.     cin >> input;
  44.     cout << "it's " <<273.15 - input << " Celsius " << endl;
  45. }
  46. void whatToWhat(char firstDegrees, char secondDegrees) {
  47.     if (firstDegrees == 'C' || 'c') {// tests if the user want form c to f
  48.         if (secondDegrees == 'F' || 'f') {
  49.             CtoF();
  50.         }
  51.     }if (firstDegrees == 'C' || 'c') {// tests if the user want form c to k
  52.         if (secondDegrees == 'K' || 'k') {
  53.             CtoK();
  54.         }
  55.     }if (firstDegrees == 'F' || 'f') {// tests if the user want form f to c
  56.         if (secondDegrees == 'C' || 'c') {
  57.             FtoC();
  58.         }
  59.     }if (firstDegrees == 'F' || 'f') {// tests if the user want form f to k
  60.         if (secondDegrees == 'K' || 'k') {
  61.             FtoK();
  62.         }
  63.     }if (firstDegrees == 'K' || 'k') {// tests if the user want form k to f
  64.         if (secondDegrees == 'F' || 'f') {
  65.             KtoF();
  66.         }
  67.     }if (firstDegrees == 'K' || 'k') {// tests if the user want form k to c
  68.         if (secondDegrees == 'C' || 'c') {
  69.             KtoC();
  70.         }
  71.     }
  72.  
  73. }
  74.     int main() {
  75.     char firstDegrees, secondDegrees;
  76.    
  77.     cout << "enter what you want to convert to what[C, K, F]" << endl;
  78.     cin >> firstDegrees;
  79.     cout << "to" << endl;
  80.     cin >> secondDegrees;
  81.     whatToWhat(firstDegrees, secondDegrees);
  82.  
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement