Resistances

This is a discussion on Resistances within the C++ Programming forums, part of the General Programming Boards category; I have to do a program calculating the total resistance of a ladder network. I've done the array and what ...

  1. #1
    hel
    hel is offline
    Registered User
    Join Date
    Dec 2001
    Posts
    3

    Resistances

    I have to do a program calculating the total resistance of a ladder network.

    I've done the array and what I think is the equation for it. There are no parse errors when I compile it but the program stops after the values have been inputted?

    Any ideas?

    heres what I have:

    #include<iostream.h>
    #include<fstream.h>
    #include"Array.h"
    #include"Text.h"
    using namespace std;
    int main()
    {
    Array<double> res;
    int NoRes;
    double ResVal;
    cout << "Welcome to the equivalent resistance calculator." << endl;
    cout << "enter the number of resistors in the circuit (must be EVEN number): ";
    cin >> NoRes;
    res.setSize(NoRes);

    cout << endl;

    double value;
    for (int n=0; n < res.size(); n++)
    {
    cout << "enter value for resistor " << n+1 << " in ohms : ";
    cin >> value;
    res(n) = value;
    }

    ResVal = res(NoRes-1);

    for (int i = NoRes-2; i>0; i=i-2)
    {
    ResVal=ResVal+res(i);
    ResVal= (ResVal*res(i-1) / (ResVal + res(i-1))) ;
    }
    ResVal=ResVal+res(0);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    21
    are you sure the program stops ? or does it complete without outputting anything further.

  3. #3
    hel
    hel is offline
    Registered User
    Join Date
    Dec 2001
    Posts
    3
    Thats what happens when I try to run it! I'm not sure whats going on!

    bash 1$ CCCs new.c
    bash 2$ a
    Welcome to the equivalent resistance calculator.
    enter the number of resistors in the circuit (must be EVEN number): 4

    enter value for resistor 1 in ohms : 4
    enter value for resistor 2 in ohms : 5
    enter value for resistor 3 in ohms : 6
    enter value for resistor 4 in ohms : 7
    bash 3$

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    21
    my point was, and although i dont really know that much about c++. i cant seem to see where you're outputting your calculated resistance

    "ResVal = res(NoRes-1);

    for (int i = NoRes-2; i>0; i=i-2)
    {
    ResVal=ResVal+res(i);
    ResVal= (ResVal*res(i-1) / (ResVal + res(i-1))) ;
    }
    ResVal=ResVal+res(0);
    cout << ResVal;
    return 0;
    }"

    should perhaps be the amendment, but the chances are im wrong, apologies if thats the case, i only just got up

  5. #5
    Unregistered
    Guest
    You're so right! Thanks!

    Cant believe I forgot that!

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21