//Calculate the ohms resistance of various wiring methods.
#include%26lt;iostream%26gt;
#include%26lt;iomanip%26gt;
using namespace std;
float vc,vcimp,p,s1,spimp;
int main()
{
cout%26lt;%26lt;"How many voice coils are there?";
cin%26gt;%26gt;vc;
if(vc%26lt;2)
{
cout%26lt;%26lt;"CANNOT CALCULATE INPEDANCE LEVELS"%26lt;%26lt;endl;
cout%26lt;%26lt;"NOT ENOUGH VOICE COILS!!!"%26lt;%26lt;endl;
}
else
cout%26lt;%26lt;"What is the impedance of each coil?";
cin%26gt;%26gt;vcimp;
p=vcimp/vc;
cout%26lt;%26lt;"The parallel impedance of the "%26lt;%26lt;vc%26lt;%26lt;" voice coils is "%26lt;%26lt;p%26lt;%26lt;" ohm(s)."%26lt;%26lt;endl;
s1=vcimp*vc;
cout%26lt;%26lt;"The series impedance of the "%26lt;%26lt;vc%26lt;%26lt;" voice coils is "%26lt;%26lt;s1%26lt;%26lt;" ohm(s)."%26lt;%26lt;endl;
spimp=s1/p;
cout%26lt;%26lt;"The series/parellel impedance of the "%26lt;%26lt;vc%26lt;%26lt;" voice coils is "%26lt;%26lt;spimp%26lt;%26lt;" ohm(s)."%26lt;%26lt;endl;
system("pause");
return 0;
}
i want "vc" to be a whole # and reject decimals...any help??
C++ ...I've got this code to figure impedances of different wiring methods for car subwoofers:?
The easiest way is to change vc to an int type. cin will ignore everything after the decimal point. Alternatively, you could input "vc" as a string, check for a decimal, and error out if there is a decimal.
Go S Pimps!
BTW, it's good practice to keep your variables local, and avoid global variables at all costs.
Reply:vc a string? what? i would make vc a "Integer" a string will have no numeric value to it you might as well tell it dog*cat... becuase the value will be lost with a string. besides, loads are not always a even number. Report It
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment