Tag Archives: #WSQ02

Homework 2: Temperature

Now our task was to biuld a program that convert the temperature mesures from Fahrenheit to Celsius degrees, and at the same time indicate if the water boils at the given temperature.

It was necessary a few calculations, cout commands and some conditionals to make it work, being this the result:

#include <iostream>
using namespace std;

double celsius(int F)
{
  int celsius = 5*(F-32)/9;
  return celsius;
}

int main ()
{
  int F;
  cout << "Give me the temperature in degrees Fahrenheit: ";
  cin >> F;

  cout << "The temperature given is equivalent to " << celsius(F) << "°C" << endl;

  if (celsius(F)<100)
    cout << "Water does not boil at this temperature (under 1 atm of pressure)" << endl;

  if (celsius(F)==100)
    cout << "Water will boil at this temperature (under 1 atm of pressure)" << endl;

  else
    cout << "Water will be completely vapor at this temperature (under 1 atm of pressure)" << endl;

  return 0;
}