Your First C++ Program

Tom Kelliher, CS17

Feb. 19, 1996

Lab Background

First, the ``nut and bolts''

A skeleton program:

#include <iostream.h>

int main()
{
   // your program is typed in here

   return 0;
}

To declare a floating point variable:

float variableName;

To input a number:

cin >> variableName;   // variableName must have been declared earlier

To output a variable:

cout << variableName;   // variableName must have been declared earlier

To output a variable and start a new line:

// variableName must have been declared earlier
cout << variableName << end;

To output a string literal:

cout << "Enter a number: ";

Some arithmetic operators:

Your Lab Assignment

Write a program to convert a temperature in degrees Fahrenheit to degrees Celsius:

  1. Prompt the user to input a temperature in degrees Fahrenheit
  2. Compute the equivalent temperature in degrees Celsius
  3. Output the temperature in degrees Celsius

Conversion equation:


Thomas P. Kelliher
Fri Feb 16 01:06:30 EST 1996
Tom Kelliher