ive finished most of the code for the following program, here's the code:
#include <iostream>
#include <cmath>
using namespace std;
int main(void)
{
double X, Z, angle, f, R, L, C;
const double PI = 4.0 * atan(1.0);
cout << "SERIES RLC CIRCUIT CALCULATION \n";
cout << "Please enter values for frequency, resistance, inductance, and capacitance. \n";
cout << "This program will calculate the impedance and the phase angle of the circuit. \n";
do
{
cout << "Enter the value of the frequency in hertz: ";
cin >> f;
if (f < 0)
{
cout << "Frequency must be non-negative \n";
}
else if (f == 0)
{
cout << "Zero frequency entered. Program terminated. \n";
cout << "Goodbye. \n";
return 0;
}
}
while (f < 0);
do
{
cout << "Enter the value of the resistor in ohms: ";
cin >> R;
if (R < 0)
{
cout << "Resistance must be non-negative. \n";
}
}
while (R < 0);
do
{
cout << "Enter the value of the inductor in henrys: ";
cin >> L;
if (L < 0)
{
cout << "Inductance must be non-negative. \n";
}
}
while (L < 0);
do
{
cout << "Enter the value of the capacitor in farads: ";
cin >> C;
if (C < 0)
{
cout << "Capacitance must be positive. \n";
}
}
while (C < 0);
cout << "\n";
X = (2*PI*f*L) - (1/ (2*PI*f*C));
Z = sqrt((R*R) + (X*X));
angle = (atan(X/R))*(180/PI);
cout << "The impedance of this series RLC circuit is " << Z << " ohms \n";
cout << "The phase angle is " << angle << " degrees \n\n";
fflush(stdin);
getc(stdin);
return 0;
}
everything calculates properly but my problem is that i want it to continue to loop after the user finishes making a calculation. so after it displays the impedance and phase angle it should go back to where it asks the user to enter the frequency. what should i do and where should i put in a extra command?
thaNks
Tags: