/* ************************************************************************** * Program name : 005_Area_of_triangle (Version 1.00) * * Author : Duck Wong * * Language : C / C++ * * Compiler : Boodshed Dec-C++ compiler Ver 3.95 * * Computer : PII350 * * O/S : Windows 98 * ************************************************************************** * Version 1.00 : 2000/06/04 - first version * ************************************************************************** * Description : (a) intut the length of 3 sides of a triangle * * (b) calculate the area of the triangle * * (c) output results * ************************************************************************** */ #include #include #include // Note (1) int main() { // part 1 : declaration float side_A, side_B, side_C, area; char YN; do // Note (2) { // part 2 : input cout << " Calculate the area of a triangle (Version 1.0)\n\n"; cout << "\a\t" << "Enter the length of Side A : "; cin >> side_A; cout << "\a\t" << "Enter the length of Side B : "; cin >> side_B; cout << "\a\t" << "Enter the length of Side C : "; cin >> side_C; cout << "\n"; // part 3 : calculate & output the result if (side_A+side_B> YN; cout << "\n\n"; } while (YN == 'Y' || YN == 'y'); // Note (3) system("PAUSE"); return 0; } /* Notes (1) Use the '#include ' because this program needs to change the format of the floating-point values. The default format is : prints w/ 4 decimal digits. (2) To execute a while statement, the computer first determine whether the expression is true or false. If expression is true, the computer execute action and return to the top of the loop. The computer repeat this process until the expression is false. The do while statement is similar to the while statement; the only different is that the expression controlling the loop is tested at the bottom of the loop. That means the body of the loop is always executed at least once (same as REPEAT...UNTIL statement in PASCAL). (3) Logical operators : &&=AND , ||=OR , ! = NOT i.e. while (YN == 'Y' || YN == 'y') means repeat the loop if YN = 'Y' or 'y' */