So I actually did this assignment awhile back, and now I have to combine the code into a new program, but when I went to test it out I realized it wasn't working. When I had submitted it I know it was working but now I can't get the bars themselves to print out, I'm thinking maybe I missed something and didn't save it? Here's the data that it should read in:
Code:
10 13
1.131232 0.000183
2.872323 0.000312
4.233291 0.000422
5.823823 0.000367
6.464139 0.000316
6.554324 0.000275
6.001023 0.000245
5.293232 0.0
7.012323 0.000612
7.013323 0.000583
Here's what it should look like:
Code:
What file stores the car data?
sample.txt
95
90
85
80
75
70
65
60
55
50
45
40
35
30 *****
25 ***** *****
20 ***** *****
15 ***** *****
10 ***** ***** *****
5 ***** ***** *****
0 ***** ***** *****
-----------------------------------
00-05 05-10 10-15 15-20 20-25 25-30
and this is what i've got:
Code:
#include<stdio.h>
#define PI 3.14159
void printGraph(int min, double milespg[]){
int x=100, a, b;
while(x != 0){x -= 5; printf("%-4d", x);
for(a = 0; a <= (min-1); a++){
for(b = 0; b < 5; b++){
if(milespg[a]>=x)
putchar('*');
else
putchar(' ');}
putchar(' ');}
putchar('\n');}
printf(" -----------------------------------\n");
printf(" 00-05 05-10 10-15 15-20 20-25 25-30\n");
}
int main(){
int min, in, a = 0, y;
double totalrev = 0, totalgas = 0, rev, gas;
char file[20];
FILE *fp;
double mpg[300];
printf("What file stores the car data?\n");
scanf("%s", &file);
fp = fopen(file, "r");
fscanf(fp, "%d", &min);
fscanf(fp, "%d", &in);
min = min / 5;
while(a <= (min-1)){
for(y = 1; y != 301; y++){
fscanf(fp, "%lf %lf", &rev, &gas);
totalrev = totalrev + rev;
totalgas = totalgas + gas;
}
mpg[a] = (PI * in * 2 * totalrev / 63360) / totalgas;
a++;
totalrev = 0, totalgas = 0;
}
printGraph(min, mpg);
fclose(fp);
system("PAUSE");
return 0;
}
Can anyone see why it wouldn't be printing out the *'s?