Converting temperatures (if statements)

// Converting Temperatures.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
       int choice;
       double ctemp, ftemp;
       cout << "1. From Celsius to Fahrenheit: " << "\n";
       cout << "2. From Fahrenheit to Celsius: " << "\n";
       cout << "Choose between 1 and 2: " << "\n";
       cin >> choice;
       if (choice == 1){
             cout << "Enter the temperature in Celsius: " << "\n";
             cin >> ctemp;
             ftemp = (1.8*ctemp)+32;
             cout << "The temperature in Fahrenheit is: " << ftemp << "\n";
       }
       if (choice == 2) {
             cout << "Enter the temperature in Fahrenheit: " << "\n";
             cin >> ftemp;
             ctemp = (ftemp - 32)/1.8;
             cout <<"The temperature in Celsius is: " << ctemp << "\n";
       }
       system("pause");
       return 0;
}




Share on Google Plus