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<iostream>
#include<math.h>
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 \n";
cout<<"\n";
do
{
cout<<"Choose a circuit \n\n";
cout<<"Press 1 for RLC SERIES circuit \n";
cout<<"Press 2 for RLC PARALLEL circuit \n\n";
cout<<"Key in your choice \n";
cin>>option;
cout<<"\n";
cout<<"Key in the value of resistance 'R'\n";
cin>>R;
cout<<"Key in the value of capacitance 'C'\n";
cin>>C;
cout<<"Key in the value of inductance 'L'\n";
cin>>L;
cout<<"Key in the frequency 'f'\n";
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));
radian=atan((xl-xc)/R);
degree=(radian*180)/pi;
cout<<"\n";
cout<<"The total impedance of RLC in series is Z = "<<z<<" ohms and "<<degree<<" degree\n";}
if (option==2)
{yr=1/R; yc=1/xc; yl=1/xl;
z=1/(sqrt((pow(yr,2)+pow((yl-yc),2))));
radian=atan((yl-yc)/(1/R));
degree=(radian*180)/pi;
cout<<"\n";
cout<<"The total impedance of RLC in parallel is Z = "<<z<<" ohms and "<<degree<<" degree\n";}
else
{cout<<"Sorry the value is invalid \n";}
cout<<"\n";
cout<<"Do you wish to continue using the calculator? \n";
cout<<"Enter 1 for yes 2 for no \n";
cin>>conti;}
while (conti==1);
cout<<"\n\n";
cout<<"Thank You For Using The Calculator \n";
system("pause");
}
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<iostream>
#include<math.h>
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 \n";
cout<<"\n";
do
{
cout<<"Choose a circuit \n\n";
cout<<"Press 1 for RLC SERIES circuit \n";
cout<<"Press 2 for RLC PARALLEL circuit \n\n";
cout<<"Key in your choice \n";
cin>>option;
cout<<"\n";
cout<<"Key in the value of resistance 'R'\n";
cin>>R;
cout<<"Key in the value of capacitance 'C'\n";
cin>>C;
cout<<"Key in the value of inductance 'L'\n";
cin>>L;
cout<<"Key in the frequency 'f'\n";
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));
radian=atan((xl-xc)/R);
degree=(radian*180)/pi;
cout<<"\n";
cout<<"The total impedance of RLC in series is Z = "<<z<<" ohms and "<<degree<<" degree\n";}
if (option==2)
{yr=1/R; yc=1/xc; yl=1/xl;
z=1/(sqrt((pow(yr,2)+pow((yl-yc),2))));
radian=atan((yl-yc)/(1/R));
degree=(radian*180)/pi;
cout<<"\n";
cout<<"The total impedance of RLC in parallel is Z = "<<z<<" ohms and "<<degree<<" degree\n";}
else
{cout<<"Sorry the value is invalid \n";}
cout<<"\n";
cout<<"Do you wish to continue using the calculator? \n";
cout<<"Enter 1 for yes 2 for no \n";
cin>>conti;}
while (conti==1);
cout<<"\n\n";
cout<<"Thank You For Using The Calculator \n";
system("pause");
}