Calculating Total Resistance in an Infinite Parallel Circuit

  • C/C++
  • Thread starter vladittude0583
  • Start date
  • Tags
    Homework
In summary: No, you don't need to store all of them. The program just needs to be able to store the values for it to calculate the total resistance for a given "n" number of resistors.
  • #1
vladittude0583
40
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
  • #2
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?
 
  • #3
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;
}
 
  • #4
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.
 
  • #5
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.
 
  • #6
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.
 
  • #7
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?
 

What is C programming?

C programming is a high-level programming language designed for system and application programming. It is a general-purpose language that is widely used for developing operating systems, web applications, and games.

What are the basic concepts of C programming?

Some of the basic concepts of C programming include data types, control structures, functions, arrays, pointers, and structures. These concepts are essential for understanding and writing programs in C.

Why do I need help with my C homework?

C programming can be challenging, especially for beginners. It requires a good understanding of programming concepts and syntax. Getting help with your C homework can not only save you time, but also improve your understanding of the language.

Where can I find help with my C homework?

There are many resources available for C homework help, including online tutorials, forums, and programming communities. You can also seek help from your instructor or classmates.

What can I do to improve my C programming skills?

Practice, practice, practice! The best way to improve your C programming skills is to write code regularly. You can also read books, watch tutorials, and participate in coding challenges to enhance your knowledge and skills.

Similar threads

  • Programming and Computer Science
Replies
8
Views
2K
  • Introductory Physics Homework Help
Replies
3
Views
603
  • Introductory Physics Homework Help
Replies
6
Views
445
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Introductory Physics Homework Help
Replies
7
Views
756
  • Introductory Physics Homework Help
Replies
6
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
901
  • Introductory Physics Homework Help
Replies
7
Views
1K
Replies
2
Views
816
  • Introductory Physics Homework Help
Replies
10
Views
1K
Back
Top