// Zig Herzog // Aug. 11, 2010 // introToVariables.cpp #include <iostream> // instruction to the compiler to include // the content of a header file which provides // information to your program about the details // of performing input (keyboard) and output (monitor) using namespace std ; // to clarify to the compiler as to how to interpret // certain names int main ( ) { double area, length, height ; // declaring three variables = // three locations in memory. // Each will hold a sequence of // 0's and 1's representing numbers // of data types "double" // User information and input from user cout << "Calculating the area of a triangle." << endl ; cout << "Give length of base line : " ; // text to monitor cin >> length ; // input from keyboard cout << "Give height of triangle : " ; // text to monitor cin >> height ; // input from keyboard // Perform calculations area = 0.5*length*height ; // Provide results to user cout << "A triangle with baseline = " << length << " and height = " << height << " has an area of " << area << endl ; } // The segment of code starting with "int main ...." constitutes // the definition of a function here of the name "main". // Each program consists of one or several such function definitions // and MUST always contain one called "main", the names of other // functions (if needed) are arbitrary, meaning they are selected by // you, the programmer. A program always starts executing with the // main function. Each function consists of several mandatory pieces : // a) data type ( "double" here ) ; // b) name ( "main" here ) ; // c) the parenthesis () which optionally contain additional information (none here) // d) the opening curly brackets { // e) the closing curly brackets } // The lines inbetween the {} contain the instructions // as to what the computer is supposed to do and are acted upon in the // order given. These lines contain a sequence of "statements" each // one concluded by a semicolon (;). By convention : A new statement // always starts on a new line. // Indentation of lines is optional, but HIGHLY recommended to improve // readability of the code which becomes EXTREMELY important when you // have to find errors in your code. Empty (blank) lines also improve // readability. // // C++ (and most other languages) is CASE-SENSITIVE !!!!!!! // ( try Main instead of main ) //