I wrote a piece of code for queuing system for a simulation. And I need to print some values to a txt file after compiling the code. I wrote the code for writing to files but although it creates the file, it does not print the values to my text file. If you can help I will appriciate. Here is the piece of code that I have...
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
int main()
{
float rho_start ; // start value of the utilization factor 
float rho_end ; // end value of the utilization factor
float rho_step ; // step value of the utilization factor
float lambda ; // ratio of customers and time
float N ; // mean number of customers in the system
float Q ; // mean number of customers in queue
float res_time ; // response time
float mu ; // service rate , assuming mu = 10 customers/s for this assignment
float i ; // for the loop
printf("Please enter the start value of the rho : ");
scanf("%f",&rho_start);
printf("Please enter the end value of the rho : ");
scanf("%f",&rho_end);
printf("Please enter the step value of the rho : ");
scanf("%f",&rho_step);
printf("Please enter the mu : ");
scanf("%f",&mu);
printf("RHO \t\t N \t\t Q \t\t RT \n");
printf("--- \t\t --- \t\t --- \t\t --- \n");
for( i = rho_start ; i < rho_end ; i = i + rho_step)
{
    N = i/(1-i) ;
    lambda = i * mu ;
    Q = (i*i)/(1-i) ;
    res_time = N/lambda ;
    printf("%.3f \t\t %.3f \t\t %.3f \t\t %.3f \n", i , N , Q , res_time);
}
    FILE * f1;
    f1 = fopen("sample.txt","w");
    if( rho_step == 0.1 )
    {   
        for(i = rho_start ; i < rho_end ; i = i + rho_step)
        {
            N = i/(1-i) ;
            fprintf(f1 , "%.3f \t\t %.3f \n" , i , N);
        }
    }
    if( f1 == NULL ) 
    {       
    printf("Cannot open file.\n");
    exit(1);
    }
    fclose(f1);
return 0;
}
 
    