Heres the source code:
// Convert temperature from Celsius to Fahrenheit & vice versa
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
int main(int nNumberofArgs, char* pszArgs[])
{
using namespace std;
string choice = "y";
char CF;
char C;
char F;
cout << "Assign Celsius to a key" << endl;
cin >> C;
cout << "Assign fahrenheit to a key" << endl;
cin >> F;
cout << endl; while (choice == "y"){
cout << "Which do you wish to convert?";
cout << endl;
cin >> CF;
if (CF == C)
{
// Celsius
double celsius;
cout << "Enter the temperature in Celsius: ";
cin >> celsius;
// Factor
double factor;
factor = 180.0;
// Celsius to fahrenheit using factor
double fahrenheit;
fahrenheit = factor * celsius/100.0 + 32.0;
// Output the results on-screen
cout << "Fahrenheit value is: ";
cout << fahrenheit << endl; cout << endl;
}else
{
double Fahrenheit;
cout << "Enter the temperature in fahrenheit: ";
cin >> Fahrenheit;
cout << Celsius << endl;
double Celsius;
Celsius = (Fahrenheit - 32)*5/9;
cout << "Celsius value is: ";
cout << endl;
}
cout << "Would you like to start again?" << endl;
cin >> choice;
system("cls");
}
system("PAUSE");
return 0;
}
Click to animate
