I need to create a graph using the console with C#, it needs to be set out like below:
0 10 20 30 40 50 60 70 80 90 100
| | | | | | | | | | |
***************************************************************** Blue
**** Red
********************** Yellow
The data will be dependent upon what the user enters as the percentage has to be calculated, each asterisk represents 2%.
My question is how to do it? How can I get the correct amount of asterisk to be shown i.e if blue equals 40% then display 20 asterix.
Thanks
Help with creating a Console Graph
Started by Alex_j, Nov 20 2009 11:03 AM
3 replies to this topic
#1
Posted 20 November 2009 - 11:03 AM
|
|
|
#2
Posted 20 November 2009 - 12:43 PM
static void Main(string[] args)
{
int percentage = 40;
string percentageToString = new string('*', percentage / 2);
Console.WriteLine(percentageToString);
Console.ReadLine();
}
#3
Posted 22 November 2009 - 06:16 AM
Thanks that works fine apart from say if the number is 17% it needs to have 9 asterisk and this only makes it have 8, so it needs to round the number to the multiple of two in a way :confused:
Any ideas of how to do this?
Any ideas of how to do this?
#4
Posted 22 November 2009 - 08:31 AM
add 1 to the percentage before you divide by 2 (I.E. force Rounding up)


Sign In
Create Account


Back to top









