Name: Anonymous 2007-10-24 15:28
Can anyone tell me why this is not working AGH?
/* This program takes information from a file and reads it and calculates volumes of wood*/
#include <stdio.h>
#include <math.h>
#define FILENAME "wood.txt"
#define PI 3.14159
int main(void)
{
/*Declare Variables*/
int num_data_pts=0;
char type;
double sum_O=0, sum_C=0, sum_P=0, vol_O=0, vol_C=0, vol_P=0, D_in, L_ft, OD_in, OL_ft, PD_in, PL_ft, CD_in, CL_ft;
FILE *wood;
/*Open file*/
wood = fopen(FILENAME, "r");
if (wood == NULL)
printf("Error opening input file. \n");
else
{
/*Read and accumulate information*/
while ((fscanf(wood, "%c %lf %lf", &type, &D_in, &L_ft)) == 1)
{
num_data_pts++;
switch (type)
{
case 'O': case 'o':
{
OD_in+=D_in;
OL_ft+=L_ft;
vol_O=(PI*(OD_in*OD_in)*OL_ft/48);
}
break;
case 'C': case 'c':
{
CD_in+=D_in;
CL_ft+=L_ft;
vol_C=(PI*(CD_in*CD_in)*CL_ft/48);
}
break;
case 'P': case 'p':
{
PD_in+=D_in;
PL_ft+=L_ft;
vol_P=(PI*(PD_in*PD_in)*PL_ft/48);
}
break;
}
/* Print information*/
printf("Number of logs processed: %d \n", num_data_pts);
printf("Volume of Oak: %10.2lf \n", vol_O);
printf("Volume of Cherry: %10.2 \n", vol_C);
printf("Volume of Pine: %10.2 \n", vol_P);
}
}
/*Exit Program */
return 0;
}
/* This program takes information from a file and reads it and calculates volumes of wood*/
#include <stdio.h>
#include <math.h>
#define FILENAME "wood.txt"
#define PI 3.14159
int main(void)
{
/*Declare Variables*/
int num_data_pts=0;
char type;
double sum_O=0, sum_C=0, sum_P=0, vol_O=0, vol_C=0, vol_P=0, D_in, L_ft, OD_in, OL_ft, PD_in, PL_ft, CD_in, CL_ft;
FILE *wood;
/*Open file*/
wood = fopen(FILENAME, "r");
if (wood == NULL)
printf("Error opening input file. \n");
else
{
/*Read and accumulate information*/
while ((fscanf(wood, "%c %lf %lf", &type, &D_in, &L_ft)) == 1)
{
num_data_pts++;
switch (type)
{
case 'O': case 'o':
{
OD_in+=D_in;
OL_ft+=L_ft;
vol_O=(PI*(OD_in*OD_in)*OL_ft/48);
}
break;
case 'C': case 'c':
{
CD_in+=D_in;
CL_ft+=L_ft;
vol_C=(PI*(CD_in*CD_in)*CL_ft/48);
}
break;
case 'P': case 'p':
{
PD_in+=D_in;
PL_ft+=L_ft;
vol_P=(PI*(PD_in*PD_in)*PL_ft/48);
}
break;
}
/* Print information*/
printf("Number of logs processed: %d \n", num_data_pts);
printf("Volume of Oak: %10.2lf \n", vol_O);
printf("Volume of Cherry: %10.2 \n", vol_C);
printf("Volume of Pine: %10.2 \n", vol_P);
}
}
/*Exit Program */
return 0;
}