Mar 10, 2010 at 6:45pm UTC
Hello there,
I'm new to C++ and I want to do a simple graph with large numbers like 96.5 to 100.
I found this in a post on this forum but is closed to replies:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <iostream>
#include <string>
std::string InsertLine(int index)
{
std::cout << "Enter the " << index + 1 << " items size in the bar graph: " ;
int itemSize;
std::cin >> itemSize;
std::string myString(itemSize, '*' );
return myString;
}
int main()
{
std::cout << "How big would you like your bar graph: " ;
int graphSize;
std::cin >> graphSize;
std::string *graph = new std::string[graphSize];
for (int i = 0; i < graphSize; i++)
{
graph[i] = InsertLine(i);
}
std::cout << "--------------------------------------------------" << std::endl;
for (int i = 0; i < graphSize; i++)
{
std::cout << i+1 << ": " << graph[i] << std::endl;
}
std::cout << "--------------------------------------------------" << std::endl;
delete [] graph;
return 0;
}
I want to use large numbers like 96.5 and 100, but this causes the * to go to far off the screen and then continue on the next line.
How can I limit the output length of the '*' to display say about 50 of the * when I type in 100?
Any help would be greatly appreciated..... Is there a simple fix? :-(
Thank you in advance....
Last edited on Mar 10, 2010 at 7:12pm UTC
Mar 10, 2010 at 9:26pm UTC
It's not mine, I did not program it. I found it on this forum.
I just want to know how to cutdown the output of the * on the screen to half, to be able to fit on one line.
Anyone know how to do this?
Thank you.....
Mar 10, 2010 at 9:55pm UTC
Thanks again, how do I now get it to work with float or double?
Mar 11, 2010 at 1:28am UTC
Well, you can't output 0.3 asterisks, so you have to decide how you want to map the data.
How much does 1 asterisk represent?
Mar 11, 2010 at 1:46am UTC
Ahh thank you jsmith. Sorry, I didn't even think of that! One asterisk equals 1, so I need them to be equal to each 0.1 entered by user.
So how can I allow the user to input of say 95.1, 95.2, 95.3, 95.4, and so on. I need the asterisk to be displayed for each number to the right of the decimal one place. For example, starting from; 1.0, 1.1, 1.2, 1.3, 1.4, and 1.5 will look like this for output:
*
**
***
****
*****
******
This is really getting me going and would love to figure this out, is it possible?
Thanks for all your help......
Last edited on Mar 11, 2010 at 1:47am UTC
Mar 11, 2010 at 2:25pm UTC
Well, it's possible, sure, but then 1.1 == 2.0, 1.2 == 3.0, 1.3 == 4.0 (when viewing the graph).