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: pieisgood 2007-08-16 11:20 ID:uwvkYoYJ

alright, thanks guys that helped a lot. I am starting to warm up to /prog/ it's like /g/ sage first, help later.

Name: Anonymous 2007-08-16 11:21 ID:Heaven

>>41
fuck you, /prog/ is nothing like /g/

Name: pieisgood 2007-08-16 11:47 ID:uwvkYoYJ

oh and here's my final source!

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



int main(int argc, char *argv[])
{
 int cols;
 int max = 30;
 int c;
 int y;
 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]);


                 cols = count[25] / max;

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

}



and >>42
Cry more

Name: Anonymous 2007-08-16 11:50 ID:cNnPpPGu

>>43
Get the FUCK out, we don't want you, we don't want you shitty broken C++

FUCK OFF

Name: pieisgood 2007-08-16 11:51 ID:uwvkYoYJ

>>44
you forgot your sage

Name: Anonymous 2007-08-16 11:53 ID:cNnPpPGu

>>45
namefag gtfo

Name: Anonymous 2007-08-16 11:55 ID:Heaven

>>43

Ha ha wow, you really fucked that one up.

Name: Anonymous 2007-08-16 12:08 ID:zO2sWqfs

oh and here's my final source!

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



int main(int argc, char *argv[])
{
 int cols;
 int max = 30;
 int c; int y; int count[26];

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


          while (! cin.eof()   !=0)          {
           if( isalpha ( c = tolower( cin.get() ) ) )     count
[ 0 - 'a' + c]+= (int)1.0f ;  // Fix for negative numbers.  -- John.
           }


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

{
                 cols = count[25] / max;
} // {
                 for (int y = max; y > 0; y--) /* } */
             {
               for (int x=
0; x < 26; x++)              {
                if (*(x+count*cols/(y==cols?y:cols)) / cols >= y)
cout.put('^') ;
                else /* } */
                cout.put (i-26);}cout.put('\n'); } // } }
                    return !main;

}

Name: Anonymous 2007-08-16 12:16 ID:Heaven

>>48

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

God he's an idiot.

Okay how about this faggot

int x;
for(x = 0; x < sizeof count / sizeof *count; count[x] = 0);


Also

while (! cin.eof()   !=0)

WHAT


your code is awful.
holy fucking shit.

Name: Anonymous 2007-08-16 12:20 ID:Heaven

>>49
WHAT?!
I DID A MISTAKE AGAIN.
DAMN I SHOUDLNT GET OUT OF BED TODAY.

for(x = 0; x < sizeof count / sizeof *count; count[x] = 0);


for(x = 0; x < sizeof count / sizeof *count; count[x++] = 0);


fixed.
sigh.

Name: Anonymous 2007-08-16 12:25 ID:zO2sWqfs


for(int *x=count+sizeof count/sizeof *count;x>count;*(--x)*=0);

Name: Anonymous 2007-08-16 12:31 ID:cNnPpPGu


(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))



Name: Anonymous 2007-08-16 12:31 ID:cNnPpPGu


(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))



Name: Anonymous 2007-08-16 12:31 ID:cNnPpPGu


(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))




(let ((freq (make-array 256 :initial-element 0)))
  (with-open-file (s "/usr/share/dict/words")
    (loop (handler-case (map nil (lambda (c) (incf (aref freq (char-code c)))) (read-line s))
        (error (_) (return)))))
  ((lambda (mmx) (map-into freq (lambda (x) (floor (* x 15) mmx)) freq)) (loop for x across freq maximizing x))
  (loop for y from 0 to 15 do
    (loop for x from 0 to 26 do (write-char (if (< (aref freq (+ (char-code #\a) x)) (- 16 y)) #\  #\#))) (terpri)) (format t "abcdefghijklmopqrstuvwxyz~%"))



Name: Anonymous 2007-08-16 12:37 ID:zO2sWqfs


((((-:-0)))
  (--(s "////")
    ((-(((c) (((-c)))) (-s))
        ((_) ()))))
  ((() (-((x) ((* x ) )) )) ())
  (y
    ((-((< ((+ (-#\a) x)) (- y)) #\  #\#))) ()) (t "~%"))

Name: Anonymous 2007-08-16 12:40 ID:s4//P3s7

0011010110101001101101001010101001010101101001001101011010100110110100101010100101010110100100110101101010011011010010101010010101011010010011010110101001101101001010101001010101101001001101011010100110110100101010100101010110100100110101101010011011010010101010010101011010010011010110101001101101001010101001010101101001001101011010100110110100101010100101010110100100110101101010011011010010101010010101011010010011010110101001101101001010101001010101101001

Name: Anonymous 2007-08-16 17:14 ID:cNnPpPGu

>>56

lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda lambda

Name: Anonymous 2007-08-16 19:39 ID:XwaK5GEv


if (count[x] / cols >= y)
   cout.put('^') ;
else
   cout.put (' ');


HELL NO!
cout.put(count[x] / cols >= y ? '^' : ' ');

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