Thread: Struggling With the Next Step.

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    8

    Struggling With the Next Step.

    Hi all, just not long started university and have now started c programming. It is very interesting and im enjoying it so far but have hit a brick wall, and need some help/guidance.

    I have got a problem/question to answer and i cant get the right code together to solve it.

    The question is to calculate the time in seconds, the time it takes for a capacitor to charge to 35%/75% and 95%. The code must prompt the user to enter values for the resistor and capacitor, in which ive done, but i cant work out how to calculate the time in seconds after calculating the time constant (roughly 63% of the capacitor full charge), the user should only see the values in seconds for the time it takes to charge to 35%,75% and 95%. Please help, here is the code i have currently got together.


    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    float timeconstant(float R, float C);
    
    
    float R;
    float C;
    float time_c;
    
    
    int main(void)
    {
    
    
        printf("State a Value For The Resistor?\n");
        scanf("%f",&R);
        printf("State a Value For The Capacitor?\n");
        scanf("%f",&C);
        time_c = timeconstant(R,C);
        printf("Time Constant is : %.2f \n" ,time_c);
    
    
        getchar();
        getchar();
    
    
    }
    float timeconstant(float R1, float C1) 
    {
        float t_constant;
        t_constant = R1*C1;
        return t_constant;
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Normally, you'd want a loop (for loop perhaps), that would loop three times. First time, a variable would be at .35, next time at .75, and then at .95. One or more if statements could be used to handle this logic.
    Code:
    if(i == 0) 
       variableName = .35;
    else if(i == 1)
       variableName = .75;
    //etc.
    Inside the loop, you would include a print statement to output the needed info.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    You have to research the formula that you require. Something like Vc = V * (1- e^(-t / R*C))
    Resistance, Capacitance, Voltage, And Time Calculator
    RC Time Calculator
    I'm not sure how the percentage charged works into this... The above sites are calculators and graphs... but they don't explain nearly enough for a programmer.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You should have the equation and explanation of it, in your notes or textbook.

  5. #5
    Registered User
    Join Date
    Nov 2013
    Posts
    8
    Quote Originally Posted by nonoob View Post
    You have to research the formula that you require. Something like Vc = V * (1- e^(-t / R*C))
    Resistance, Capacitance, Voltage, And Time Calculator
    RC Time Calculator
    I'm not sure how the percentage charged works into this... The above sites are calculators and graphs... but they don't explain nearly enough for a programmer.
    The formula ive been provided with are these:

    VC/VS = 0.35;0.75;0.95
    VC / VS = 1- e t/RC

    I dont understand how the percentages will be linked in with the formula and be used as the supply voltage? The question doesn't state a power supply or voltage of any sort?

  6. #6
    Registered User
    Join Date
    Nov 2013
    Posts
    8
    Quote Originally Posted by Adak View Post
    Normally, you'd want a loop (for loop perhaps), that would loop three times. First time, a variable would be at .35, next time at .75, and then at .95. One or more if statements could be used to handle this logic.
    Code:
    if(i == 0) 
       variableName = .35;
    else if(i == 1)
       variableName = .75;
    //etc.
    Inside the loop, you would include a print statement to output the needed info.
    Havent done much work on loops yet so will have to try research it, this question is really killing me, our lecturer is one of those who just expects you to know what to do without explaining the basics.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Dobblaar View Post
    The formula ive been provided with are these:

    VC/VS = 0.35;0.75;0.95
    VC / VS = 1- e t/RC

    I dont understand how the percentages will be linked in with the formula and be used as the supply voltage? The question doesn't state a power supply or voltage of any sort?
    I think your instructor is expecting you to know what "percentage" means. For instance, Vc/Vs is a percentage (comparing the current voltage to the maximal voltage, albeit with the percentage expressed as a decimal).
    I also think your instructor is expecting you to know "algebra", in that you will need to solve that formula for t.

  8. #8
    Registered User
    Join Date
    Nov 2013
    Posts
    8
    Quote Originally Posted by tabstop View Post
    I think your instructor is expecting you to know what "percentage" means. For instance, Vc/Vs is a percentage (comparing the current voltage to the maximal voltage, albeit with the percentage expressed as a decimal).
    I also think your instructor is expecting you to know "algebra", in that you will need to solve that formula for t.
    He's told us that the formula is to be used in the code and the program is meant to calculate each value, not us inputting the data manually which will be effortless. Having a hard time understanding all of this as of yet, i can work it out manually with a set voltage of course, but don't know how to input the formula into the code to do all the calculations?

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Dobblaar View Post
    He's told us that the formula is to be used in the code and the program is meant to calculate each value, not us inputting the data manually which will be effortless. Having a hard time understanding all of this as of yet, i can work it out manually with a set voltage of course, but don't know how to input the formula into the code to do all the calculations?
    He's not expecting you to write code to solve arbitrary equations; he's expecting you to rearrange the formula (to get a "new" formula that starts "t = ") and use that formula to compute time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-08-2013, 03:16 AM
  2. Step by step read data from exe file to memory.
    By JoBlack in forum C++ Programming
    Replies: 1
    Last Post: 06-23-2012, 02:02 PM
  3. Replies: 4
    Last Post: 05-26-2011, 06:51 AM
  4. multiplying step by step
    By Martin0027 in forum C Programming
    Replies: 1
    Last Post: 05-18-2011, 11:03 AM
  5. why does the memory increase step by step?
    By zcrself in forum C Programming
    Replies: 9
    Last Post: 07-14-2010, 12:04 AM