Calculating Total Resistance in an Infinite Parallel Circuit

  • Context: C/C++ 
  • Thread starter Thread starter vladittude0583
  • Start date Start date
  • Tags Tags
    Homework
Click For Summary

Discussion Overview

The discussion revolves around calculating the total resistance of an infinite parallel circuit using a programming approach. Participants explore coding strategies for handling an unspecified number of resistors, focusing on user input and loop structures in C programming.

Discussion Character

  • Homework-related
  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant questions how to code for an "infinite" number of resistors and suggests the need for a while loop.
  • Another participant suggests that an infinite number may not be practical and questions whether all individual resistor values need to be stored for total resistance calculation.
  • A participant shares their current C program code, detailing how it calculates total resistance based on user input of resistor values.
  • Multiple coding strategies are proposed, including asking the user for the number of resistors or using a sentinel value to terminate input.
  • There is a discussion on where to declare the number of resistors in the code and whether it should be part of the loop or outside of it.
  • One participant clarifies the formula for calculating total resistance in parallel and questions the necessity of storing all resistor values if they are input one at a time.

Areas of Agreement / Disagreement

Participants present various coding approaches and opinions on the necessity of storing resistor values, indicating that there is no consensus on the best method to implement the solution.

Contextual Notes

Some participants express uncertainty about the best coding practices for handling user input and calculations, and there are unresolved questions about the efficiency of different approaches.

vladittude0583
Messages
40
Reaction score
0
Hey guys, our homework requires us to write the code to calculate the total resistance of a circuit for "n" number of resistors in parallel. My question is what kind of coding scheme is required for the "n" number of resistors which basically means "infinite" number of resistors?

I know there is a while loop involved, however, I cannot seem to figure out how to make the program accept an infinite number of resistor values?

Your help is greatly appreciated. Thanks.
 
Technology news on Phys.org
They probably don't want an infinite number, it would take rather a long time to enter!
Look at the formula for resistors in parallel, do you need to store all the individual values to calculate th etotal resistance so far?
 
Yes, the program needs to be able to store the values for it to calculate the total resistance for a given "n" number of resistors. This is what I have coded so far in my C program,

#include <stdio.h>

#define SENTINEL 0

int main()
{

double r;
double value;
double total = 0.0;
double resistanceTotal;

printf("Welcome, this program is designed to calculate the \n"
"total equivalent resistance of a circuit for a given \n"
"\"n\" number of parallel resistors. \n\n");

while(1)
{
printf("\nPlease enter the value of your resistor(s) now! \n"
"Press \"0\" at anytime to terminate the program. \n\n");
scanf("%lf", &r);

if (r == SENTINEL || r < SENTINEL)
{
break;
}

else if (r > SENTINEL)
{
value = 1/r;
total += value;
resistanceTotal = 1/total;
printf("%2.2lf ohms", resistanceTotal);
}


}

printf("\nProgram Author: Vladimir S. Lolinco \n\n");

system("pause");
return 0;
}
 
This can be done in a number of ways. Here's two -

1. Ask the user how many resistors they have, then use that input to set up the loop.

2. Choose a value to terminate the loop (q for quit, or 0, or another similar invalid input) and then just keep looping until the user enters the "end" value.
 
So, I know I would declare the number of resistors the user has as a double, but where would I place that "value" in my while loop? Would that be part of a calculation in the while loop or outside of it? Am I even on the right track for my calculations? Thanks.
 
Since you're using a while loop, option 2 is probably a better bet. Plus, that seems to be what you're doing anyway.

If you were using a for loop, then option 1 might be a more natural fit. You CAN use option1 with a while loop (by using a counter variable inside the loop) but IMO it's not as clean.


Really, you're almost there with what you have. Think some more about what mgb_phys posted, and consider what should be inside the loop and what should be outside.
 
Isn't the resistance of a bunch of resistors in parallel
1/R =1/R1 + 1/R2 + ... 1/Rn
If you are given the resistances one at a time, do you need to store all of them?
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 29 ·
Replies
29
Views
10K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K