home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-3.ZIP / EXAMPLES.ZIP / BARCHART.C next >
C/C++ Source or Header  |  1992-02-18  |  1KB  |  60 lines

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