I am trying to do my assignment but I cant figure out how to get 8 data points per line to print to a file.
Here is the assignment
1. Program asks the user to enter an odd number as a BASE, using this Base it creates 48 multiples of the BASE and prints in a data file "data_3b.tx t", 8-data per line.
2. Program opens this data file, scans the contents of "data_3b.tx t" file and counts all the odd data, and prints them on the screen: 4 data per line.
3. Program computes the average of all the odd data. It prints the number of odd data points and their average on the screen in the given FORMAT.
I havent even gotten to reading the file, which I dont think I can do anyway. I'm still trying to figure out how to get 8 data points on one line, LOL! Here is my program so far. Sorry its not right justified. Can someone please help me. Also how am I supposed to tell the program to stop reading whenever I get to that part!
thanks for any help
[CODE=c]#include <stdio.h>
#include <math.h>
int main (void)
#define FILENAME "data_21.tx t"
#define CRT_SECURE_NO_D EPRECATE
{
double base;
int p, t, count, q, m, k;
FILE *data_2;
printf("enter an odd number as base");
scanf_s("%lf", &base);
data_2=fopen("d ata.txt","w");
for (p=9;p<=15;p++)
{
base=base*p;
for(k=1;k<=8;k+ +)
{
m=base*k;
fprintf(data_2" %20d",m);
}
printf("\n");
}
data_2=fopen("d ata.txt","r");
fscanf(data_2," %lf",&m);
return 0;
}[/CODE]
Here is the assignment
1. Program asks the user to enter an odd number as a BASE, using this Base it creates 48 multiples of the BASE and prints in a data file "data_3b.tx t", 8-data per line.
2. Program opens this data file, scans the contents of "data_3b.tx t" file and counts all the odd data, and prints them on the screen: 4 data per line.
3. Program computes the average of all the odd data. It prints the number of odd data points and their average on the screen in the given FORMAT.
I havent even gotten to reading the file, which I dont think I can do anyway. I'm still trying to figure out how to get 8 data points on one line, LOL! Here is my program so far. Sorry its not right justified. Can someone please help me. Also how am I supposed to tell the program to stop reading whenever I get to that part!
thanks for any help
[CODE=c]#include <stdio.h>
#include <math.h>
int main (void)
#define FILENAME "data_21.tx t"
#define CRT_SECURE_NO_D EPRECATE
{
double base;
int p, t, count, q, m, k;
FILE *data_2;
printf("enter an odd number as base");
scanf_s("%lf", &base);
data_2=fopen("d ata.txt","w");
for (p=9;p<=15;p++)
{
base=base*p;
for(k=1;k<=8;k+ +)
{
m=base*k;
fprintf(data_2" %20d",m);
}
printf("\n");
}
data_2=fopen("d ata.txt","r");
fscanf(data_2," %lf",&m);
return 0;
}[/CODE]
Comment