Example 1:   convert.cpp

/////////////////////////////////////////////////////////////////
//  Name
//  CS10-01
//  Fall 2006
//  Lab Assignment 1
//  File: convert.cpp
//  Description: convert temperature from Fahrenheit to Celsius
//  Compile: g++ -o convert convert.cpp
////////////////////////////////////////////////////////////////

#include<iostream>
using namespace std;

#define CONVERSION_FACTOR  (5.0/9.0)

int main(void)
{
  double fahrenheit,   // temperature in Fahrenheit
         celsius;      // temperature in Celsius

  // Get temperature in Fahrenheit
  cout << "Enter the temperature in Fahrenheit: ";
  cin  >> fahrenheit;

  // Convert to Celsius
  celsius = (fahrenheit-32)*CONVERSION_FACTOR;

  // Print temperature in Celsius
  cout << fahrenheit << " degrees Fahrenheit is equivalent to "
       << celsius  << " degrees Celsius.\n";

  return(0);
}
 
 


If you find any errors, please report them to: ptantalo@soe.ucsc.edu

webmaster@soe.ucsc.edu

Back to the SOE Class Home Pages
Back to the SOE Home Page