Histogram help

D

DeLiLlaH

hi all ;

-------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{

int gd = DETECT, gm, kod, i,x,y,a,x1;
initgraph(&gd, &gm, "C:\Dev-Cpp\bin");
kod graphresult();

x=getmaxx();
y=getmaxy();
a=x/12; x1=10;

randomize();
line(0,0,0,y);
line(0,y,x,y);

for (i=0; i<6; i++)
{
setfillstyle(i,random(getmaxcolor()));
bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);
x1=x1+a*2;
}
getch();
closegraph();
}

----------------------------------------------------------------------------------------------------------------------

or

------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
int i, j, mark[] = {7,6,9,4,7,7,5,10,8,6,5};
for ( i = 0; i < sizeof mark / sizeof *mark; ++i )
{
printf("%2d|", i + 1);
for ( j = 0; j < mark; ++j )
{
fputs(" ", stdout);
}
puts("*");
}
puts(" +----------------------");
puts(" 0 1 2 3 4 5 6 7 8 9 10");
return 0;
}

---------------------------------------------------------------------------------------------------------------


First one is a 3d bar graphics and second is a histogram graphic,
How can I do first or second graphics for the numbers that I'll enter
randomly ??
 
M

Malcolm McLean

DeLiLlaH said:
hi all ;

-------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<graphics.h>
main()
{

int gd = DETECT, gm, kod, i,x,y,a,x1;
initgraph(&gd, &gm, "C:\Dev-Cpp\bin");
kod graphresult();

x=getmaxx();
y=getmaxy();
a=x/12; x1=10;

randomize();
line(0,0,0,y);
line(0,y,x,y);

for (i=0; i<6; i++)
{
setfillstyle(i,random(getmaxcolor()));
bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);
x1=x1+a*2;
}
getch();
closegraph();
}

----------------------------------------------------------------------------------------------------------------------

or

------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

int main(void)
{
int i, j, mark[] = {7,6,9,4,7,7,5,10,8,6,5};
for ( i = 0; i < sizeof mark / sizeof *mark; ++i )
{
printf("%2d|", i + 1);
for ( j = 0; j < mark; ++j )
{
fputs(" ", stdout);
}
puts("*");
}
puts(" +----------------------");
puts(" 0 1 2 3 4 5 6 7 8 9 10");
return 0;
}

---------------------------------------------------------------------------------------------------------------


First one is a 3d bar graphics and second is a histogram graphic,
How can I do first or second graphics for the numbers that I'll enter
randomly ??

The api, which is not standard C, seems to be basiclaly a wrapper for this
function

bar3d(x1,random(y)+20, x1+a, y-1,a/2,1);

The first four parameters look like x, y coordinates of the corners, the
other parameerts are preasumably colour, line thickness, and so on, but I
cannot quite decipher.

However we can adjust the call easily enough.

int randinput[6];

/* enter the random numbers in a loop using scanf() */
for(i=0;i<6;i++)
scanf("%d\n" &randinput);

for(i=0;i<6;i++)
bar3d(i*10, randinput, i*10+10, 1, something, somethingelse);

with any luck this will place a bar where you want it. You might have to
fiddle with the values - I've assumed you want 10 pixel wide bars going from
1 to the random number. Also the two extra parameters you'll have to look
up - not being familiar with the call I can't work everything out from one
code sample.
 
R

Richard Heathfield

CBFalconer said:
Errors so far: No such std include files as <conio.h> or
<graphics.h>.

They're not errors. They merely render the program non-portable.
main returns an int, say so.

He did, using the "implicit int" rule. Not good style, perhaps, but
*not* an error.
 
O

Old Wolf

CBFalconer said:

They're not errors. They merely render the program non-portable.

Well, conforming compilers could report an error on
those lines, and refuse to compile the code. Perhaps
that is what CBFalconer meant.
 
R

Richard Heathfield

Old Wolf said:
Well, conforming compilers could report an error on
those lines, and refuse to compile the code. Perhaps
that is what CBFalconer meant.

Perhaps. I agree that discussions of extensions would render this group
unusable, but I wish we could say so without suggesting that
non-portable code presented here is somehow /wrong/. What's wrong is
not the code (necessarily) but the choice of newsgroup in which to post
it.
 
M

Mark McIntyre

Perhaps. I agree that discussions of extensions would render this group
unusable, but I wish we could say so without suggesting that
non-portable code presented here is somehow /wrong/. What's wrong is
not the code (necessarily) but the choice of newsgroup in which to post
it.

<mode=mild sarcasm>
Richard has apparently been travelling on the Road to Damascus...
</mode>
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
A

Army1987

CBFalconer said:
Errors so far: No such std include files as <conio.h> or
<graphics.h>. main returns an int, say so. If main takes no
arguments, say so with "int main(void)". c.l.c deals with the
standard C language as described in the various C standards. Other
things are off-topic.
6.10.2:
A preprocessing directive of the form
# include <h-char-sequence> new-line
searches a sequence of implementation-defined places for a header identified
uniquely by
the specified sequence between the < and > delimiters, and causes the
replacement of that
directive by the entire contents of the header. How the places are specified
or the header
identified is implementation-defined.

One should use <> for headers provided by the implementation,
wheter they're standard or not, and "" for the ones he wrote himself. The
only "error" is assuming that people in comp.lang.c are familiar with
something which is not on topic here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top