Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create a frequency distribution printout that give the nubmer fo cities reportin

ID: 3627014 • Letter: C

Question

create a frequency distribution printout that give the nubmer fo cities reporting accident counts in the following ranges:
0-99
100-199
200-299
300-399
400-499
500 or more
1.Must use an array for the counts of the accident ranges
2.results must be displayed in tabular format
3. 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.
4.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 for the range array

Explanation / Answer

#include <stdio.h>
#include <conio.h> // remove this if u are in linux
void updateRange(int a[],int count)
{
if(count >=500)
a[5]++;
else if(count>=400 && count <=499)
a[4]++;
else if(count>=300 && count <=399)
a[3]++;
else if(count>=200 && count <=299)
a[2]++;
else if(count>=100 && count <=199)
a[1]++;
else if(count>=0 && count <=99)
a[0]++;
}

void displayRange(int a[])
{
      printf("    Range       Frequency            " ) ;
      printf("    0-99                %d ", a[0]);
      printf("   100-199             %d ", a[1]);
      printf("   200-299             %d ", a[2]);
      printf("   300-399             %d ", a[3]);
      printf("   400-499             %d ", a[4]);
      printf("   500 or above        %d ", a[5]);
}


int main ()
{
    int temp;
    int a[6]={0,0,0,0,0,0};   

    printf("Enter a accidents count or enter -1 to stop> ");
    do
    {
        scanf("%d", &temp);

        if (temp == -1)
            break;
  updateRange(a,temp);
  printf(" Enter a accidents count or enter -1 to stop> ");
        } while (temp != -1);
        displayRange(a);

getch();

return (0);

}