home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / BARCHART.C next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  1.3 KB  |  56 lines

  1. #include           <stdio.h>
  2. #include           <stdlib.h>
  3. #include           <float.h>
  4. #include           <graphics.h>
  5. #include           <math.h>
  6. #include           <conio.h>
  7.  
  8. #define            MAX        50
  9. #define            ARRAYMAX   10
  10.  
  11. void makegraph(float p[]);
  12.  
  13. void main(void)
  14. {
  15.   int              i;
  16.   int              scores[ARRAYMAX];
  17.   float            percents[ARRAYMAX];
  18.  
  19.   for (i = 0; i < ARRAYMAX; i++)
  20.     {
  21.     printf("\nEnter score between 0 and %d:  ", MAX);
  22.     scanf("%d", &scores[i]);
  23.     }
  24.   for (i = 0; i < ARRAYMAX; i++)
  25.     percents[i] = ((float) scores[i]) / MAX;
  26.  
  27.   printf("\n\n\n\tSCORE\tPERCENT");
  28.   for (i = 0; i < ARRAYMAX; i++)
  29.     printf("\n%d. \t%d\t%3.0f", i + 1, scores[i], (percents[i] * 100));
  30.   getch();
  31.   makegraph(percents);
  32. }
  33.  
  34. void makegraph(float p[])
  35. {
  36.   int              g_driver, g_mode;
  37.   int              i, left, top, wide, bottom, deep;
  38.  
  39.   detectgraph(&g_driver, &g_mode);
  40.   initgraph(&g_driver, &g_mode, "..\\bgi");
  41.   wide = (int)((getmaxx()) / ((ARRAYMAX * 2 ) + 1));
  42.   bottom = getmaxy() - 20;
  43.   deep = (int) (wide / 4);
  44.   left = wide;
  45.   for (i = 0; i < ARRAYMAX; i++)
  46.     {
  47.     top = (bottom) - ((int)(p[i] * 300));
  48.     bar3d(left, top, (left + wide), bottom, deep, 1);
  49.     left += (wide * 2);
  50.     }
  51.   getch();
  52.   closegraph();
  53.   return;
  54. }
  55. 
  56.