ok I have a project for my C programming class due pretty soon but I can't seem to get the darn output file to contain any of the variables values.
Code:
#include <stdio.h>
int main (void)
{
double V,I, R1, RL, vR1, vR2, vRL, PR1, PR2, PRL,RS;
int count;
int R2;
FILE *f= NULL;
f = fopen("G:\\Projects\\ET156-C Programming\\DC-Final Project\\Final Project Data\\data.txt","a");
fprintf(f,"%s","\nR1+R2\t\tRL Power\tPower R2\tPower R1\tRL\n");
fprintf(f,"%s","---------\t------------\t------------\t--------\t---\n");
printf("this program will repeat 10 times\n");
while(count<10){
//Asks for voltage
printf("Please input a value between 1 & 15 for the Voltage: ");
scanf("%lf", &V);
//if voltage is not within parameters asks for a different voltage
if (V<15.4 && V>0.4);
else{
printf("Please use a voltage between 1 & 15: ");
scanf("%lf", &V);
}
//asks for a value for RL
printf("Please enter a value between 0 & 5000 for RL: ");
scanf("%lf", &RL);
if (RL<5000.4 && RL>-0.6);
else{
printf("Please use a load resistance between 0 & 5k ohms: ");
scanf("%lf", &RL);
}
//RS must equal RL for Max Power Transfer
R1 = 100;
R2 = RL - 100;
RS = R1 + R2;
//Formulas used to calculate Maximum Power Transfer
I = V /(RS + RL);
vR1 = I * R1;
vR2 = I * R2;
vRL = I * RL;
PR1 = I * vR1;
PR2 = I * vR2;
PRL = I * vRL;
fprintf(f,"%d","\n\n %f\n\t\t %g \t\t %g \t\t %g \t\t %g \f\n" , RS, PRL, PR2, PR1, RL);
printf("Maximum power transferred to RL is %.3lf Watts\n\n\n\n", PRL);
count++;
}
fclose (f);
return (0);
}
that is the code that I have written so far. any help with the last fprintf would be much appreciated.
thanks