### Author Topic: Programming Exercise - Cosine Law  (Read 7018 times)

#### louiecerv

• Moderator
• User
•     • Posts: 85 ##### Programming Exercise - Cosine Law
« on: December 08, 2005, 05:58:19 PM »
Code: [Select]
`/*  Name:         Cosine Law  Author:       LF Cervantes  Date:         12/08/05  Description:  First Programming Exercise (ITE205-IT)*/#include <iostream>#include <cmath>using namespace std;int main(){        cout << "-- COSINE LAW --\n\n";        cout << "A program that illustrates the cosine law.\n";        int b, c;        float a, Angle;        const double PI = 3.14159;        char answer;        do        {            cout << "\nEnter length of sides b and c as two integers\n";            cout << "   separated by space    : ";            cin >> b >> c;            cout << "Enter angle between side b and side c (degrees)  : ";            cin >> Angle;                        a = sqrt(pow(b, 2.0) + pow(c,2.0) -                     2 * b * c * cos (Angle * PI / 180));                        cout << "length of side a = " << a;                        cout << "\n\nRepeat run with new input? y/n : ";            cin >> answer;        }  while ( answer == 'y' || answer == 'Y');        cout << endl;          system("PAUSE");    return 0;}`

Highlights:
Do-While loop
Math statements
Analyze. Design. Develop. Debug. Deploy. Maintain.