/******************************* PARALLEL.CPP *********************************
* Example showing variables and operators                          1998-09-23 *
*                                                                   Agner Fog *
*                                                                             *
* This program calculates the value of two resistors in parallel              *
******************************************************************************/
// include libraries:
#include <iostream.h>
#include <conio.h>

// main is where program execution begins:
void main ()
{
   // declare variables:
   float R1, R2, Rp;

   // input values of resistors R1 and R2:
   cout << "\nPlease enter value of R1 ";
   cin >> R1;
   cout << "\nPlease enter value of R2 ";
   cin >> R2;

   // check if parameter values are allowed:
   if (R1 + R2 == 0)
   {
      // avoid dividing by zero:
      cout << "\nError: Result cannot be calculated";
   }
   else
   {
      // calculate result:
      Rp = R1 * R2 / (R1 + R2);

      // output result:
      cout << "\nThe value of the parallel combination is ";
      cout << Rp;
   }

   // wait for user to press a key:
   getch();
}

Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates