My group and I are writing a program that can solve Resistance total, Voltage total and Current total in a DC series, parallel, and series-parallel circuit. We have the whole program written already but we cannot get the parallel part of the program to work. We have the program setup to have up to 5 resistors for series and 5 for parallel, the series part works perfectly and give you the correct total resistance. When you enter the resistance values for the parallel part (lines 73 to 82)of the circuit it gives us the incorrect total resistance if you enter values for less than 5 resistors. Example if the circuit only has 3 resistors in parallel you enter the 3 values and the other 2 resistors you have to enter 0’s for the values and it will give you the incorrect resistance total. If you enter 5 resistor values it gives us the correct number. We think the reason we are getting the incorrect value is because you have to enter a 0’s.
We need help in figuring what we can do to get the parallel part to work. We tried rewriting the program to first ask the user how many resistors are in parallel to avoid entering 0’s but we could not get it to work probably because we are all beginners in programming. Any assistance is appreciated.
Unless you need to remember the individual values, you don't really need to use an array in the first place which is forcing you to use 0 if < 5 values are entered. You could still test if res == 0 then add 0 to resPTot, else add res^-1 to resPTot though. If you don't need to save the values, you could just keep adding them to the total until the user said they were done or, if you do, you could use a vector.