Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How to print vertical lines in a graph in C++

Name: pieisgood 2007-08-16 2:42 ID:zUDRSrwb

ok... so I have been working on a stupid program that takes in characters one at a time and then counts then and then prints out how many characters there are and a graph.. but I don't know how to make my graph vertical... can any one /prog/ help a fool like me?

source:

#include <stdio.h>
#include <iostream>
#include <cctype>
using namespace std;



int main(int argc, char *argv[])
{
 int cols;
 int max = 80;
 int c;
 int y;
 int k;

 int count[26];

 for (int x = 0; x < 26; x++)
 count[x] = 0;

          while (! cin.eof())
          {
           if( isalpha ( c = tolower( cin.get() ) ) )


              count [ c - 'a']++ ;  // for everytime a certain value appears add 1 to that values number and when it shows up again add another 1 = 2





           }


                 for (int i = 0; i < 26; i++)
                 printf("[%c] = %d\n" , i+'a' , count[i]);



                   for (int x=0; x<26; x++)
             {

                if (count[x] > 1)
                {


                    cols =  max * count[x] / count[25] ;


                  for (int y=0; y < cols; y++)

                           cout.put('-') ;
                         cout.put ('\n');
                        }
                    }





  return 0;

}

Name: Anonymous 2007-08-16 8:40 ID:Heaven

// FUCK YOU LISP CRAP

#include <iostream>
#include <algorithm>

using namespace std;

#define DEFAULT_GRAPH_HEIGHT 20

int main(int argc, char *argv[])
{
        int graph_height = 0;

        if (argc>1)
        graph_height = atoi(argv[1]);

        if (graph_height<=0)
                graph_height = DEFAULT_GRAPH_HEIGHT;

        int count[26] = {0};
        int c;

        while(!cin.eof())
                if (isalpha(c = tolower(cin.get())))
                        count[c-'a']++;

        int max_count = 0;

        for(int i=0;i<26;i++)
                max_count = max(max_count, count[i]);

        int bar_ratio = max_count / graph_height;

        for(int y=graph_height;y>0;y--)
        {
                for(int x=0;x<26;x++)
        {
                        if ((count[x]/bar_ratio)>=y)
                                cout.put('#');
                        else    cout.put(' ');
        }
                cout.put('\n');
        }

        for(c='a';c<='z';c++)
                cout.put(c);

        cout.put('\n');

        return 0;
}

Name: Anonymous 2007-08-16 8:49 ID:Heaven


        while(!cin.eof())
                if (isalpha(c = tolower(cin.get())))
                        count[c-'a']++;

god the stupidity.
SERIOUSLY FUCKING FIXED:

while(c = cin.get)
if(isalpha(c)) count[tolower(c)-'a']++;

Name: Anonymous 2007-08-16 8:50 ID:HW6/JAEU

>>22
WHAT?!
YOU FAGS CONFUSED ME FUCK
I MENT
while((c = cin.get()) != EOF)
FUCKING CHRIST

Name: Anonymous 2007-08-16 8:59 ID:Heaven

>>22
WHA THE FUCK IS GOING ON WITH ME TODAY


while((c = getc(stdin)) != EOF)
if(isalpha(c)) count[(c | 1 << 5) - 'a']++;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List