Thread: Hi everyone can someone help me write this bar chart idk how to write it

  1. #1
    Registered User
    Join Date
    Oct 2021
    Posts
    2

    Hi everyone can someone help me write this bar chart idk how to write it

    Problem Description

    Write a program to display a bar chart of the input data.

    [Input form]

    Read multiple (not more than 30) positive integers (greater than 0 and less than or equal to 20) from standard input, ending with -1. Separate each integer with a space.

    【Output form】

    The histogram of each number is displayed on the screen in turn (the "*" character represents the histogram, and the blank space is represented by space characters).

    【Sample input】

    5 12 8 6 1 4 -1

    [Sample output]

    *
    *
    *
    *
    **
    **
    ***
    ****
    **** *
    **** *
    **** *
    ******

    [Sample description]

    A total of 6 positive integers were entered, namely: 5 12 8 6 1 4. Therefore, the leftmost column should output 5 bars denoted by "*", followed by 12, 8, 6, 1, and 4 bars denoted by "*".

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,796
    https://cboard.cprogramming.com/announcement.php?a=39
    Make an effort.
    Just dumping your assignment isn't good enough.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2021
    Posts
    64
    Here's a hint:

    The problem statement explicitly calls for column displays. And it appears to require the columns to correspond directly to the numbers entered. So you cannot reorder the numbers into ascending order or anything.

    Therefore, make a 2-d array of chars, and fill it with either stars or spaces. Then you can quickly output the array without worrying about what it contains, whether it is too high or too low, or anything like that.

    This lets you separate out the "printing" from the "computing." It should make things easier for you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lot of WRITE calls in parallel in C WRITE test code
    By Bobby1995 in forum C Programming
    Replies: 2
    Last Post: 04-28-2020, 08:47 AM
  2. Replies: 9
    Last Post: 09-09-2014, 08:23 AM
  3. how to re write this in C
    By jeromey55 in forum C++ Programming
    Replies: 27
    Last Post: 03-07-2011, 08:04 AM
  4. What's the best way to write this?
    By claphahat in forum C Programming
    Replies: 4
    Last Post: 07-29-2010, 04:53 AM
  5. problem with fout.write: cannot write 0x0A (10 dec)
    By yvesdefrenne in forum C++ Programming
    Replies: 7
    Last Post: 05-23-2005, 12:53 PM

Tags for this Thread