Advertisement
jhnksr

Temperature Converter

Sep 28th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.    
  6.     int choice;
  7.     float input, conversion;
  8.    
  9.     //here is used to select the conversions.
  10.    
  11.     cout << "Temperature Conversions Select a number to Proceed:" << endl;
  12.     cout << "1. Degree Farhenheit to Degree Celcius" << endl;
  13.     cout << "2. Degree Celcius to Degree Fahrenheit" << endl;
  14.     cout << "Enter your choice: ";
  15.     cin >> choice;
  16.     //if choice 1 is selected then only the first line of code will be executed
  17.     if (choice == 1)
  18.     {
  19.         cout << "Enter the Degree Fahrenheit Value: ";
  20.         cin >> input;
  21.         conversion = (input-32) / 1.8;
  22.         cout << "The temperature in degree celcius is: " << conversion << " °C";
  23.     }
  24.     // if choice 2 is selected, the else statement will run, insread of the if statement.
  25.     else
  26.     {
  27.         cout << "Enter the Degree Celcius Value: ";
  28.         cin >> input;
  29.         conversion = (1.8 * input) + 32;
  30.         cout << "The temperature in degree fahrenheit is: " << conversion << " °F";   
  31.     }
  32.  
  33.     return 0;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement