# Graphics Problem!

• 03-15-2006
Eddie K
Graphics Problem!
Hey - wonder if anyone can have a look at this and see what's up with it. It's meant to take an array of xcoordinates and ycoordinates from an earlier piece of code and then plot the straight fit line of those points. For some reason though I'm not reading the arrays into the function properly or something, because I'm getting gobbledeegook.

Regards.

Code:

```void plot(float xcoords[], float ycoords[], int numpoints)       {           float xmax, ymax, xmin, ymin;           float xpixels [1000], ypixels [1000];           int xres, yres;               //Prints input data as a check.           printf("x\t    y");           printf("\n---------------------------\n");           int i;           for (i=0;i<numpoints;i++) {                                     printf("%f\t    %f\n", xcoords[i], ycoords[i]);                                     }//End Loop.                                           //INITIALISE GRAPHICS MODE AND SETUP SCREEN:               GrSetMode(GR_default_graphics);           xres = GrScreenX();           yres = GrScreenY();                     //SCALING:               xmax = maximum(xcoords, numpoints); //Call "maximum" function.           ymax = maximum(ycoords, numpoints);                     xmin = minimum(ycoords, numpoints); //Call "minimum" function.           ymin = minimum(ycoords, numpoints);               int xpixmin = xres - 20;           int ypixmin = yres - 20;           int xpixmax = xres;           int ypixmax = yres;                     for(i=0;i<numpoints;i++) {                                     xpixels[i] = xpixmin + ((xcoords[i]-xmin)*(xpixmax-xpixmin));                                     ypixels[i] = ypixmin + ((ycoords[i]-ymin)*(ypixmax-ypixmin));                                     } // End loop.                                               printf("xres is %d and yres is %d \n", xres, yres);           printf("\n\nx pixel\t    y pixel");           printf("\n-----------------------------\n");               for (i=0;i<numpoints;i++) {                                     printf("%f\t    %f\n", xpixels[i], ypixels[i]);                                     }                                         // DRAW AXES:               GrLine(20, yres - 20, xres, yres - 20, 9); // x-axis.           GrLine(20, yres - 20, 20, 20, 9); // y-axis.               // DRAW CURVE OR LINE:                             float xp = xpixels[0], yp = ypixels[0];           for(i=1;i<numpoints;i++) {                                     GrLine((int)xp, (int)yp, (int)xpixels[i], (int)ypixels[i], 4);                                     xp = xpixels[i];                                     yp = ypixels[i];                                     } // End loop.           // EXIT GRAPHICS SCREEN               printf("Enter any key to continue...\n");           scanf("%d", &xp);           GrSetMode(GR_default_text);           }               plot(xp, yp, n); // Calls function.```
• 03-15-2006
qqqqxxxx
try printing out the values of (int)xp ,(int)yp,cuz u may not find what u r expecting.
• 03-17-2006
dwks
Code:

```          printf("Enter any key to continue...\n");           scanf("%d", &xp);```
There are better ways to wait for the user to "press <enter> to continue": see the FAQ.