|
-
March 1st, 2011, 11:03 PM
#1
Help with Summations in Program
I'm working on an assignment program that will help users find the equivalent resistance of various AC and DC circuits. It involves doing a summation with a for loop. I'm just really stuck on how to implement this loop.
I understand the reason I'm using this is because it's the only loop that will run a certain number if iterations the user specifies, I'm just having trouble translating the math into a code.
So in this case if it's a bunch of resistors in series you just add all the resistances to get the equivalent resistance. What I'm stuck on is how to get the program to continually ask the user the resistance the number of iterations previously established by the user, and have the program continue to sum until the number of iterations is satisfied.
Here's the code I have so far for just this test, not my actual program.
Code:
#include <iostream>
using namespace std;
int main(void)
{
int nRes, r_i, x;
cout << "How many resistors? >";
cin >> nRes;
for (x = 1; x < nRes; x = x + r_i)
cout << "Next resistance? >";
cin >> r_i;
system("PAUSE");
return EXIT_SUCCESS;
}
.
This is really starting to tick me off cause this is the last piece of the code I need, and it should be easy but I'm not gettin it. HINTS PLEASE!?!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|