Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

RLC Impedance Calculator

Posts: 3Member
Guys i have a small problem. i made a program coding where the impedance of two different types of circuits are to be calculated. it work fine but there is a small problem. okay let me just give a brief explanation about how this program should work. when u start the program, the user will be given a choice to either select a series circuit or a parallel circuit. once the user has selected the type of circuit, the programs goes on with by asking the user to key in R, L, C and f and then it calculates the impedance and displays the answer. the problem is that i need to make sure if the user keys in any other number to choose the circuit, it should display invalid input. for example
press 1 for series
press 2 for parallel
if the user presses any other number besides 1 and 2, it should display the "invalid input' statement. it does happen but u have to renter the values R,L,C and f all over again n then it displays the statement.
this is my program coding :

#include
#include
using namespace std;
void main()
{
double R, yr, L, yl, f, C, yc, option, conti, pi=3.142;
double xc, xl, z, radian, degree;
cout<<" RLC Impendance Calculator
";
cout<<"
";
do
{
cout<<"Choose a circuit

";
cout<<"Press 1 for RLC SERIES circuit
";
cout<<"Press 2 for RLC PARALLEL circuit

";
";
cin>>option;
cout<<"
";
cout<<"Key in the value of resistance 'R'
";
cin>>R;
cout<<"Key in the value of capacitance 'C'
";
cin>>C;
cout<<"Key in the value of inductance 'L'
";
cin>>L;
cout<<"Key in the frequency 'f'
";
cin>>f;

xc=1/(2*pi*f*C);
xl=2*pi*f*L;

if (option==1)
{z=sqrt(pow(R,2) +pow((xl-xc),2));
cout<<"
";
cout<<"The total impedance of RLC in series is Z = "<<z<<" ohms and "<<degree<<" degree
";}

if (option==2)
{yr=1/R; yc=1/xc; yl=1/xl;
z=1/(sqrt((pow(yr,2)+pow((yl-yc),2))));
cout<<"
";
cout<<"The total impedance of RLC in parallel is Z = "<<z<<" ohms and "<<degree<<" degree
";}

else
{cout<<"Sorry the value is invalid
";}
cout<<"
";
cout<<"Do you wish to continue using the calculator?
";
cout<<"Enter 1 for yes 2 for no
";
cin>>conti;}

while (conti==1);
cout<<"

";

cout<<"Thank You For Using The Calculator
";

system("pause");
}

· ·