Hi,
I was wondering if anyone could tell me how I could write a program where there is a number scale and a certain number when read from the input will represent it in accordingly to the scale. any help will be appreciated. thanks
Hi,
I was wondering if anyone could tell me how I could write a program where there is a number scale and a certain number when read from the input will represent it in accordingly to the scale. any help will be appreciated. thanks
@Nasser - welcome to the forum!
Say I want the input to fit into a graph with 0-100 for it's range. My data numbers are ranging from 0 to 10,000.
Take 10,000, and divide it down, until it is 100, or just barely less than that.
Since 10000 / 100 = 100, all my data numbers need to be divided by 100, to scale properly.
This worked out "perfectly" with all integers, but in real life, you may want to use a float or double, and "walk" it down in a loop:
The above is not meant to be a runnable bit of code. Just an idea, expressed in code form.Code:float factor = 1.00, highest_data, graph_scale = 100; while((highest_data /factor) > graph_scale) { factor += .01; }
Last edited by Adak; 03-26-2011 at 03:50 AM.
Sorry, I don't think you understood me. what I mean to say is, say:
Input = 3.
And then output would be:
1---2---3----4----5----6
(blank )xxxxx
(Everything before "x" is blank)
I'm assuming the "1---2---3----4----5----6" would be printed using printf() but I'm not sure how to locate the "3" and print "x" on the graph.
Thanks
When I'm making a graph, I like to first, put the whole thing into an array.
Then just print up the array. That helps because I can jump around in the rows and columns of the array, much easier than I can when printing it on the screen.
The answer to your question is to multiply 2 * the width of each "column" of the graph, +1. If the column has space for a 2 digit number, and then 4 spaces after it, that's 6 spaces total, so three's column begins at the 13th space over from the left margin. (the left margin of the graph will not be the left margin of the screen most likely, so add that value in, as well.)
I'm sorry I'm have trouble understanding what you explained. What are the "columns"? Could you explain it in a different way?
Thanks
I'll try with a visual:
The first row shows a bar graph style, with value equal to 3.0. The second row shows a point graph, where the value equals 4.0Code:1----2----3----4----5----6 xxxxxxxxxxx ...............x
From the left side, until it reaches the 2, is the first column, from the 2 until it reaches the 3, is column two, etc.
To put a mark at 6, I'd go to (width of column) * 5 +1.
Last edited by Adak; 03-26-2011 at 06:20 AM.
That's actually quite easy... If you use a known number of dashes between your numbers... Say, the number and 3 dashes... then you have a number every 4th space... So to put an X under the 3, you need to move over 8 spaces (2 sets of 4)... Just print the required number of spaces followed by an X...