Results 1 to 4 of 4

Thread: C++ problem     submit to reddit submit to twitter

  1. #1
    Old Merits
    Join Date
    Jan 2007
    Posts
    1,218
    BG Level
    6
    FFXIV Character
    Zap Brannigan
    FFXIV Server
    Balmung
    FFXI Server
    Bahamut

    C++ problem

    I know a couple of you know C++ i'm trying to write a program that tells me resonance frequencies of a RLC circuit. I have everything almost done but i have to show the frequency at 10% below and above resonance and 20 intervals between them and also the impedance at same interval using the frequency at that interval, now comes the problem I was able to do the frequency fine but for some reason when i try to add the impedance the whole program comes wrong and only shows me 1 entry(solution or w/e you want to call it) instead of 20. Here's what i have so far maybe you can find what i did wrong. I think the problem is on the "for" part.

    --------------------------------------------------------------------------------------
    // examen(parte2).cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include "math.h"

    int _tmain(int argc, _TCHAR* argv[])
    {float R,L,C,Fo,XL,XC,x,x1,x2,x3,x4;

    printf("Entre el valor de la resistencia: ");
    scanf("%f",&R);
    printf("Entre el valor del inductor: ");
    scanf("%f",&L);
    printf("Entre el valor del condensador: ");
    scanf("%f",&C);
    Fo = 1/(2*3.14159265*sqrt(L*C));
    printf("Frecuencia en resonancia es %f\n",Fo);
    x1 = Fo*0.90;
    printf("Frecuencia en resonancia a 10 porciento por debajo es %f\n",x1);
    x2 = Fo+(Fo*0.10);
    printf("Frecuencia en resonancia a 10 porciento por encima es %f\n",x2);

    for(x=x1; x<=x2; x = x+(x2-x1)/20)
    {
    XL = 2*3.14159265*x*L;
    XC = 1/(2*3.14159265*x*C);
    x3 = (XL-XC)*(XL-XC) + R*R;
    x4 = sqrt(x3);

    printf("frecuencia= %f Impedancia= %f \n",x,x4) ;

    }


    getchar();
    getchar();





    return 0;
    }
    ------------------------------------------------------------------------------------
    program should look like this

    http://i34.photobucket.com/albums/d1...resonancia.png

  2. #2
    E. Body
    Join Date
    Jan 2007
    Posts
    2,103
    BG Level
    7

    I don't know if this is intended or not, but your for loop only loops on the XL term, nothing else gets looped in there. Use {}'s around what you want it to loop on.

  3. #3
    Old Merits
    Join Date
    Jan 2007
    Posts
    1,218
    BG Level
    6
    FFXIV Character
    Zap Brannigan
    FFXIV Server
    Balmung
    FFXI Server
    Bahamut

    Quote Originally Posted by Eliseos View Post
    I don't know if this is intended or not, but your for loop only loops on the XL term, nothing else gets looped in there. Use {}'s around what you want it to loop on.

    My bad i forgot to add the last review i did to my program, but the problem still exist.

  4. #4
    Sea Torques
    Join Date
    Jun 2007
    Posts
    698
    BG Level
    5
    FFXI Server
    Cerberus

    easier to use a while

Similar Threads

  1. Computer problems.
    By Amarok in forum General Discussion
    Replies: 52
    Last Post: 2005-05-13, 12:17