i am probably doing something wrong with the for loop and i don't fully understand arrays
but i basically want the program to count resistors in parallel
and out put the amount of resistance
/* Perpose: This program finds the resistons of a amount of resistors in parall
Equation: 1/r = 1/R1........1/R6......1/R8 */
#include <iostream>
usingnamespace std;
int main()
{
// declare varibles
char Again;
bool Running = true;
int NumOfResistors;
float Denominator[Dsize]; // compiler says this is undeclared
float Numerator[Nsize]; // compiler says this is undeclared
int Dsize; // compiler says this is undeclared
int Nsize; // compiler says this is undeclared
while(Running)
{
system("CLS");
cout <<" _______________________________________ " << endl;
cout <<" _|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_ " << endl;
cout <<" Welcome to the parell resistor counter " << endl;
cout <<" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl << endl << endl;
cout <<" Please type in the amount of resistors: ";
cin >> NumOfResistors;
for(int Resistor; NumOfResistors >= Resistor && 0 <= NumOfResistors; Resistor++ )
{
cout << " Type in the resistors ohms: ";
cin >> Denominator;
Numerator[Nsize] = 1;
Nsize++;
Dsize++;
}
cout <<"Nsize: " << Nsize << endl;
cout <<"Dsize: " << Dsize << endl;
// ask user if they would like to rerun the program
cout << " Would you like to run this program again (y or n) " << endl;
cin >> Again;
switch(Again)
{
// if the user says types y keep the program running
case'y':
break;
// if the user types n end the program and exit loop
case'n':
Running = false;
break;
default:
// if the user types any other letter display massage
cout << " this is a invalid value " << endl;
}
}
system("PAUSE");
return 0;
}
float Denominator[Dsize];
float Numerator[Nsize];
You must use a fixed number. The array size can't be determined at runtime. You must change to using a vector or set a hard limit on array size.
1 2 3 4 5 6 7 8 9 10
//pseudocode
// totalres = 1 / ( 1/R1 + 1/R2...+1/Rn )
int i;
for ( i = 1; i == NumResistors; i++);
resistor[i-1] = 1 / resistor[i-1]; // invert each resistor
for ( i = 1; i == NumResistors; i++);
//add the inverted resistors
totalres = 1/totalres ; invert the sum from above