Graphing Vertical Histogram

0 Samuel Egiefameh · March 28, 2015
Hello I need help graphing my vertical Histogram.

I'm able to get the graph, but now I need help getting the border on the other side of the graph to align it with the right side of my screen.

The output looks like that right now because I'm currently playing around with my yaxis (right under the for loop) trying to scale everything.

I've tried everything many different ways to get this to work. Can anyone offer some assistance?
Here's my code.

#include
#include


int main(void)
{

int MAX = 0; //initialize and declare variables
int allcounts [10] = {0}; //store an array of integers for
int xaxis = 0;
float yaxis = 0.0;
int index = 0;
int counter1 = 0;
char c = 178;
char d = 255;
char b = 179, y = 192, z = 196;
int i = 1;
int batch = 0, measurement;
int count1 = 5, count2 = 6, count3 = 7, count4 = 8, count5 = 10;
int a;



printf("%c", 201); 
for(a = 0; a < 78; a++) printf("%c", 205); printf("%c", 187);
printf("%c\t\t\t   HEIGHT OF BLACK CHERRY TREES\t\t\t       %c",186,186);
printf("%c",199); for(a=0; a= 0.1; yaxis--) //yaxis for my histogram
{
printf("%c\t%.1f%c\t\t\t%c",186,yaxis/10.0, b,186,186);
//printf("\n\t%4c",b);

//output data in histogram format

if(MAX == yaxis) //prints ASCII unto screen if true
{
MAX == count1 ? (printf("%c%c%c%c",c,c,c,c), count1--, printf("   ")): printf("       ");
MAX == count2 ? (printf("%c%c%c%c",c,c,c,c), count2--, printf("   ")): printf("       ");
MAX == count3 ? (printf("%c%c%c%c",c,c,c,c), count3--, printf("   ")): printf("       ");
MAX == count4 ? (printf("%c%c%c%c",c,c,c,c), count4--, printf("   ")): printf("       ");
MAX == count5 ? (printf("%c%c%c%c",c,c,c,c), count5--, printf("   ")): printf("       ");
MAX--; 
}
printf("\n");

}
printf("\t%4c", y);

//loop for ACCII character
for (counter1; counter1 < 50; counter1++)
printf("%c",z);

printf("\n");
printf("\t   ");

//loop for xaxis
for (xaxis; xaxis < 5; xaxis++)
{
printf("%4d\t ", xaxis + 1);
}


printf("\n\n\n\n\n");
system("pause");

}

My output is supposed to look somewhat like this. I'm not worried about the scaling part, just need help with the actual borders around the graph. Thanks for your help in advance.
/images/forum/upload/2015-03-28/d375261a7ac2ea2f1ff399bed8682dd4.jpg

Post a Reply

Replies

Oldest  Newest  Rating
0 Samuel Egiefameh · March 28, 2015
My apologies sir.

I know how to space, but I just posted incorrectly.

Any help would be greatly appreciated.


Here's my code:



int main(void)
{    
     
        int    MAX = 0; //initialize and declare variables
        int allcounts [10] = {0}; //store an array of integers for
        int xaxis = 0;
        float yaxis = 0.0;
        int index = 0;
        int counter1 = 0;
        char c = 178;
        char d = 255;
        char b = 179, y = 192, z = 196;
        int i = 1;
        int batch = 0, measurement;
        int count1 = 5, count2 = 6, count3 = 7, count4 = 8, count5 = 10;
        int a;
 
 
 
 
 
 
                    printf("%c", 201); 
                    for(a = 0; a < 78; a++) printf("%c", 205); printf("%c", 187);
                    printf("%c\t\t\t   HEIGHT OF BLACK CHERRY TREES\t\t\t       %c",186,186);
                    printf("%c",199); for(a=0; a<78; a++) printf("%c",205); printf("%c",182); 
                    //for(a=0; a<78; a++) printf("%c",' '); printf("%c",186);
                    //printf("\n\n");    
 
 
     
                    allcounts[0] = count1;
                    allcounts[1] = count2;
                    allcounts[2] = count3;
                    allcounts[3] = count4;
                    allcounts[4] = count5;
     
                         
     
                    //Determine max occuring number
                    do
                    {
                        allcounts[index] >= MAX ? MAX = allcounts[index]:printf(""); //program to determine highest number
                        index++;
                    } while(index < MAX);
 
 
                    //printf("\n\n");
                    for (yaxis = 10.0; yaxis >= 0.1; yaxis--) //yaxis for my histogram
                    {
                        printf("%c\t%.1f%c\t\t\t%c",186,yaxis/10.0, b,186,186);
                        //printf("\n\t%4c",b);
         
                        //output data in histogram format
 
 
                        if(MAX == yaxis) //prints ASCII unto screen if true
                        {
                            MAX == count1 ? (printf("%c%c%c%c",c,c,c,c), count1--, printf("   ")): printf("       ");
                            MAX == count2 ? (printf("%c%c%c%c",c,c,c,c), count2--, printf("   ")): printf("       ");
                            MAX == count3 ? (printf("%c%c%c%c",c,c,c,c), count3--, printf("   ")): printf("       ");
                            MAX == count4 ? (printf("%c%c%c%c",c,c,c,c), count4--, printf("   ")): printf("       ");
                            MAX == count5 ? (printf("%c%c%c%c",c,c,c,c), count5--, printf("   ")): printf("       ");
                            MAX--; 
                        }
                        printf("\n");
                     
                    }    
                        printf("\t%4c", y);
 
 
                        //loop for ACCII character
                    for (counter1; counter1 < 50; counter1++)
                        printf("%c",z);
         
                    printf("\n");
                    printf("\t   ");
 
 
                    //loop for xaxis
                    for (xaxis; xaxis < 5; xaxis++)
                    {
                        printf("%4d\t ", xaxis + 1);
                    }
 
 
 
 
    printf("\n\n\n\n\n");
    system("pause");
             
}
0 Samuel Egiefameh · March 28, 2015
Are you that snippet of code isn't finding the max occurring number and that's the problem with my code?
  • 1

C

107,000 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator