# Thread: Struggling With the Next Step.

1. ## 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. 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. 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. You should have the equation and explanation of it, in your notes or textbook. 5. Originally Posted by nonoob 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. Originally Posted by Adak 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. Originally Posted by Dobblaar 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. Originally Posted by tabstop 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. Originally Posted by Dobblaar 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 