Hi there is there anyone who can help, I have managed to write this programme in C and it works!! ( first time for everything ).
The problem is that the programme asks for a time increment but the returned value is not in seconds how can I adapt the programme to return the values in second(s) intervals upto the final returned value?
CODE
#include<stdio.h>
#include<math.h>
bool Check(float P, float Vf, float Vin)
{
float diff = Vf-Vin;
if(diff<0)
diff *= -1;
if(diff<P)
return 0;
return 1;
}
float CalcVolt(float Vin, float R1, float R2, float C, int t)
{
float Vout;
Vout = float(Vin * (R2/(R1+R2)) * (1 - exp (-t * (R1+R2)/(C*R1*R2))));
return Vout;
}
void Voltage(float Vin, float Vf, float R1, float R2, float C, int t, float Percentage)
{
float Vout;
int i = 0;
do
{
Vout = CalcVolt(Vin, R1, R2, C, i*t);
i += t;
printf("At t = %3d : Vout = %5.3f Volts\n", i*t, Vout);
}
while(Check(Percentage, Vf, Vout));
}
int main()
{
float Vf, Vin, R1, R2, C;
float Percentage[3] = {0.1f, 0.05f, 0.01f};
int choice;
int t;
printf("Enter Value of Vin: ");
scanf("%f", &Vin);
printf("Enter Value of R1: ");
scanf("%f", &R1);
while(R1<0)
{
printf("Negative value not allowed. Enter again. ");
scanf("%f", &R1);
}
printf("Enter Value of R2: ");
scanf("%f", &R2);
while(R2<0)
{
printf("Negative value not allowed. Enter again. ");
scanf("%f", &R2);
}
printf("Enter Value of Capacitor: ");
scanf("%f", &C);
while(C<0)
{
printf("Negative value not allowed. Enter again: ");
scanf("%f", &C);
}
printf("Enter Value of t (time increment): ");
scanf("%d", &t);
while(t<0)
{
printf("Negative value not allowed. Enter again: ");
scanf("%d", &t);
}
printf("Enter Value of Vf (final Voltage): ");
scanf("%f", &Vf);
printf("\nEnter 1 for 10%% of final value\n");
printf("Enter 2 for 5%% of final value\n");
printf("Enter 3 for 1%% of final value\n");
printf("Percentage : ");
scanf("%d", &choice);
while(choice<1 || choice>3)
{
printf("Invalid choice, Enter again: ");
scanf("%d", &choice);
}
printf("\n");
Voltage(Vin, Vf, R1, R2, C, t, Percentage[choice-1]);
return 0;
}
This post has been edited by Pegasus: 17 Feb, 2008 - 06:48 AM