1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

//power and ohms law calculator, statement input is to decide wanted outputs with obtained numerical inputs
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
void main()
{
char Statement[25]; //space for character input
double V, P, I, R, Amps, Volts, Watts, Ohms;
cout<<"Enter two of the following with 'and' between them\nvoltage, power, resistance or current."<<endl;
cin>>Statement;
if (_stricmp("voltage and power", Statement)("power and voltage", Statement)==0)
//_stricmp is string compare, if Statement is voltage and power or other way round.
{
cout<<"Enter Current"<<endl;
cin>>I;
cout<<"Enter Resistance"<<endl;
cin>>R;
Watts=(I*I)*R;
Volts=I*R;
cout<<"The Results are, "<<Volts<<" V\n"<<endl;
cout<<Watts<<" W"<<endl;
}
else if (_stricmp("current and power",Statement)("power and current", Statement)==0)
//_stricmp is string compare, if Statement is current and power or other way round.
{
cout<<"Enter Voltage"<<endl;
cin>>V;
cout<<"Enter Resistance."<<endl;
cin>>R;
Watts=(V*V)*R;
Amps=V/R;
cout<<"The Results are, "<<Amps<<" A\n"<<endl;
cout<<Watts<<" W"<<endl;
}
else if (_stricmp("resistance and power", Statement)("power and resistance", Statement)==0)
//_stricmp is string compare, if Statement is resistance and power or other way round.
{
cout<<"Enter Current."<<endl;
cin>>I;
cout<<"Enter Voltage."<<endl;
cin>>V;
Watts=V*I;
Ohms=V/I;
cout<<"The Results are, "<<Ohms<<" Ohms\n"<<endl;
cout<<Watts<<" W"<<endl;
}
else if (_stricmp("voltage and current", Statement)("current and voltage", Statement)==0)
//_stricmp is string compare, if Statement is voltage and current or other way round.
{
cout<<"Enter Power."<<endl;
cin>>P;
cout<<"Enter Resistance."<<endl;
cin>>R;
Amps=sqrt(P/R);
Volts=sqrt(P*R);
cout<<"The Results are, "<<Volts<<" V\n"<<endl;
cout<<Amps<<" A"<<endl;
}
else if (_stricmp("voltage and resistance", Statement)("resistance and voltage", Statement)==0)
//_stricmp is string compare, if Statement is voltage and resistance or other way round.
{
cout<<"Enter Current."<<endl;
cin>>I;
cout<<"Enter Power."<<endl;
cin>>P;
Ohms=P/(I*I);
Volts=P/I;
cout<<"The Results are, "<<Volts<<" V\n"<<endl;
cout<<Ohms<<" Ohms"<<endl;
}
else if (_stricmp("resistance and current", Statement)("current and resistance", Statement)==0)
//_stricmp is string compare, if Statement is voltage and current or other way round.
{
cout<<"Enter Power."<<endl;
cin>>P;
cout<<"Enter Voltage."<<endl;
cin>>V;
Ohms=(V*V)/P;
Amps=P/V;
cout<<"The Results are, "<<Ohms<<" Ohms\n"<<endl;
cout<<Amps<<" A"<<endl;
}
}
