Computer Science Canada

Simple Temperature Program

Author:  Kingnoz [ Tue Sep 02, 2003 1:07 pm ]
Post subject:  Simple Temperature Program

this is a simple temperature program i did using VC++ under win32 console application...it is simple but incorporates many things like user-defined functions, cin, cout, declaring integers.

the code is commented on to help ppl understand

code:

// temperature.cpp - converts Celsius to Fahrenheit
#include <iostream>
using namespace std;

int Celsius;        //declares Celsius
int Fahrenheit;  //declares Fahrenheit

void temp(int);   // function prototype for temp()
int main()
{
        cout << "Please enter a Celsius value: ";              //displays the question in ("") on the screen
        cin >> Celsius;  // asks the user for the integer Celsius
        temp(Celsius);    //calls the temp function
        return 0;
}

void temp(int Celsius)  //the void is used to say that temp has no return value
{
        Fahrenheit = Celsius * 1.8 + 32.0;      //formula to change Celsius to Fahrenheit
        cout << "The temperature " << Celsius <<
        " degrees Celsius is equal to " << Fahrenheit << " degrees Fahrenheit.\n";      //displays the Celsius then the equivalent Fahrenheit
}


: