NAME: SAPUNGAN, JOHN ALVIN B DATE: April 26, 2024
SECTION: BSSE - 1201
ACTIVITY 3: LOOPS
(QUIZ)
Resistor Manager and Total Resistance Calculator
Instructions:
1. Options:
Your program must present the following options repeatedly:
● Add a resistor: Choose this option to add a resistor to the circuit.
● Calculate total resistance: Choose this option to calculate the total resistance of the
circuit.
● Exit: Choose this option to exit the program.
1. Adding a Resistor:
● Enter the resistance value of the resistor when prompted.
● The program will validate the input to ensure it consists of valid characters
('0' to '9' and '.').
● If the resistance value is valid and greater than zero, it will be added to the list of
resistors, and a confirmation
message will be displayed.
● If the resistance value is not valid or less than or equal to zero, an appropriate error
message will be
Displayed.
2. Calculating Total Resistance:
● If no resistors have been added yet, the program will display a message indicating that
no resistors have been
added.
● If resistors are present:
● The user must be prompted to enter the connection type (series or parallel).
● For Series Connection:
● The program will sum up all the resistance values to calculate the total resistance.
The total resistance value will be displayed with two decimal places.
● For Parallel Connection:
● The program will calculate the total resistance using the formula:
Total Resistance = 1 / (1/R1 + 1/R2 + 1/R3 + ...) (Reciprocal of the sum of reciprocals of
all resistances)
● It iterates over each resistance value, calculates its reciprocal, and sums them up.
● Finally, it takes the reciprocal of the sum to obtain the total resistance of the parallel
circuit. The total resistance value will be displayed with two decimal places.
3. Exiting the Program:
● Choose this option to exit the program gracefully.