开发者

bar3d(),graph going out of range

开发者 https://www.devze.com 2023-01-08 16:24 出处:网络
I have made a program in graphics but when ever i enter any value in the graph it reaches its peak #include <graphics.h>

I have made a program in graphics but when ever i enter any value in the graph it reaches its peak

 #include <graphics.h>
#include <dos.h>
#include <graphics.h>
#include <conio.h>
#define LEFT 5
#define BOT 300
#define BWIDTH 10
#define TOPFLAG 1
#define BDEPTH 4
#define SEPARATION 12
#define SPACE 15
#define N开发者_C百科 10
#define TOP 5
#define PPD (float(BOT)-TOP)*100
#define DI (BWIDTH+SEPARATION)
#define WIDTH (N+1)*DI
void main(void)
{
    int driver=DETECT;
    int mode;
    initgraph(&driver,&mode,"C:\\TC\\bgi");
    cleardevice();
    rectangle(LEFT,TOP,LEFT+WIDTH,BOT);
    int arr[N]={1,2,3,4,5,6,7,8,9,10};
    for(int i=0;i<N;i++)
    {
    setfillstyle(SOLID_FILL,1+i%3);
    bar3d(SPACE+LEFT+i*DI,BOT-(arr[i]*PPD),LEFT+SPACE+i*DI+BWIDTH,BOT,BDEPTH,TOPFLAG);



}



    getch();
    closegraph();





}


Hans is right, but I think you have a * where you want a / - the definition of PPD should be:

#define PPD (((BOT)-(TOP))/100.0)

Now, come join us in the 21st century!

0

精彩评论

暂无评论...
验证码 换一张
取 消