# Thread: Need Help With Array and Arguements Hw

1. ## Need Help With Array and Arguements Hw

hi, well i need help with my hw, it deals with arrays and arguments but i have no idea how to do it, like im taking a online class and the book is basically useless, so i was wondering if u guys could help out a bit .

This is the hw problem:

Problem Description

Each year the Department of Traffic Accidents receives accident count reports from a number of cities and towns across the country. To summarize these reports, the department provides a frequency distribution printout that gives the number of cities reporting accident counts in the following ranges:
0 – 99
100 – 199
200 – 299
300 – 399
400 – 499
500 or above

The department needs a computer program to take the number of accidents for each reporting city or town and add one to the count for the appropriate accident range. After all the data have been processed, the resulting frequency counts are to be displayed.

Problem Requirement
a) You must create a file and save it as Program7.c file.
b) You must use an array for the counts of the accident ranges.
c) The results must be displayed in a tabular format.
d) The program must have one user-defined function named updateRange with 2 arguments: accident count and the range array. The function should use the accident count to increase the count for the appropriate accident range array.
e) The program must have another user-defined function named displayRange with the range array as the argument. The function should use a loop to display the content of the range array.
f) Your program should run correctly with the same inputs and outputs as given in the sample run.

This is wht i have so far :/ i know its not right

Code:
```#include <stdio.h>

main()
{

int index, a, b, c, d, e, f, city;
printf("Enter current city\n");
scanf("%lf", city);

for(index=0; index < 99; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf",a[index]);

}

for(index=0; index < 100-199; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf", b[index]);

}

for(index=0; index < 200-299; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf", c[index]);

}

for(index=0; index < 300-399; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf", d[index]);

}

for(index=0; index < 400-499; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf", e[index]);

}

for(index=0; index < 500; index++)

{

printf("Enter number of accidents in current city\n");
scanf("%lf", f[index]);

}

printf("The accident count for the current city is [index]\n");

return 0;

}```

2. I'm unclear what format you want for the frequency distribution printout. Could you show what you want? (use code tags so the format will be preserved). What you show doesn't look much like a "tabular format".

Can you be more specific than "I know it isn't right"? You know that isn't REALLY too helpful, of course.

3. You need to define arrays. When you do scanf("%lf",a[index]) it looks like you want 'a' to be an array. You must define a[6] or whatever number of elements you need. Also, you need to have '&' (address of) scanf("%lf",&a[index]).
Also, "%lf" is for type double, yet 'a' is int. You have to decide if you need integer or floating point.

Syntax for for(index=0; index < 100-199; index++) is wrong. You have to figure out what you want here.

4. None of a through f are arrays... you can't index them!

5. this is the code i wrote but i need to write it in array form but i dont know how, ohh the system pause cause a syntax error

Code:
```#include <stdio.h>

int main (void)
{
int temp;
int fivehun, fourhun, threehun, twohun, onehun,zero;
char x;

fivehun      = 0;
fourhun      = 0;
threehun     = 0;
twohun       = 0;
onehun       = 0;
zero         = 0;

printf("Enter a accidents count or enter -1 to stop> \n");

do
{
scanf("%d", &temp);

if (temp == -1)
break;
if(temp >= 500)
fivehun++;

printf("Enter a accidents count or enter -1 to stop> \n");
if(500 < temp && temp <= 400)
fourhun++;
if(400 < temp && temp <= 300)
threehun++;
if(300 < temp && temp <= 200)
twohun++;
if(200 < temp && temp <= 100)
onehun++;
if(100 < temp && temp <= 0)
zero++;

} while (temp != -1);

printf("%d fivehun, %d fourhun and %d threehun, %d twohun %d onehun %d zero\n", fivehun, fourhun, threehun,twohun,onehun,zero);

system ("pause");

return (0);
}```

6. Code:
```if(500 < temp && temp <= 400)
fourhun++;```
Oh C'mon! That's not even a good try -- work it out with a paper and pencil.

Here, temp would have to be both greater than 500 and less than or equal to 400.

Check all your if statements and see if they make sense.

7. oo got wrong sign :P so is there a way to write it in array form? a example would be nice

here its all updated it works and gives the right answer it just isnt in array form which the damn teacher didnt teach us how -.-' example plz?
Code:
```#include <stdio.h>

int main (void)
{
int temp;
int fivehun, fourhun, threehun, twohun, onehun,zero;
char x;

fivehun      = 0;
fourhun      = 0;
threehun     = 0;
twohun       = 0;
onehun       = 0;
zero         = 0;

printf("Enter a accidents count or enter -1 to stop> ");

do
{
scanf("%d", &temp);

if (temp == -1)
break;
if(temp >= 500)
fivehun++;

printf("Enter a accidents count or enter -1 to stop> ");
if(500 > temp && temp >= 400)
fourhun++;
if(400 > temp && temp >= 300)
threehun++;
if(300 > temp && temp >= 200)
twohun++;
if(200 > temp && temp >= 100)
onehun++;
if(100 > temp && temp >= 0)
zero++;

} while (temp != -1);

printf("    Range       Frequency            \n" ) ;
printf("    0-99                %d\n ", zero);
printf("   100-199             %d\n ", onehun);
printf("   200-299             %d\n ", twohun);
printf("   300-399             %d\n ", threehun);
printf("   400-499             %d\n ", fourhun);
printf("   500 or above        %d\n ", fivehun);

system ("pause");

return (0);

}```

8. For a summary, I'd use something like:

int data[SIZE];

Where SIZE is a #defined macro in your program, before int main(void).

Then the data points that would go into zero, would be recorded as:

data[0]++;

And those for one hundred would be logged in as

data[1]++;

data[4]++ would count up what group of hundreds, then?

Since you want to sum up 0 through 5, you need int data[SIZE], where SIZE is defined as 6.

9. ohh ok i think i got it thanks

10. You're welcome.