So i have a project where i need to store 8 integers, between 1-10, and recall them into a histogram The histogram is made up of the character * only. (forgive bad formatting, this is my first post) The program works, but i think my if statements for int restriction (1-10) could be simplified. My goal is to achieve this output with as little code as possible
The whole code, and nothing but the code (and comments)
Console.WriteLine("Hello and Welcome!\nEnter 8 values between 1 and 10\n*Press Any Key to continue*");
Console.ReadKey();
//create list to store values
List<int> values = new List<int>();
//loop to collect values
for (int i = 1; i < 9; i++)
{
//label for data validation start point
retry:
Console.WriteLine("Please Enter Value " + i, "Between 1 - 10");
//variable assigned to user input
value = Console.ReadLine();
//Convert string to integer
if (!int.TryParse(value, out validValue))
{
Console.WriteLine("~Incorrect Data Input~"); goto retry; };
if (validValue < 1) { Console.WriteLine("~Incorrect Data Input~"); goto retry; };
if (validValue > 10) { Console.WriteLine("~Incorrect Data Input~"); goto retry; };
values.Add(validValue);
}
for (int i = 0; i < 8; i++ )
{
Console.WriteLine();
for(int id = 0; id < values[i]; id++)
Console.Write("*");
}
Console.ReadKey();
This is the area im thinking could be cleaner
if (validValue < 1) { Console.WriteLine("~Incorrect Data Input~"); goto retry; };
if (validValue > 10) { Console.WriteLine("~Incorrect Data Input~"); goto retry; };
Im open to any suggestions as to how i could clean this or any part of the project up.
There is a more difficult aspect to this project, like a do this if you want to show off kind of thing, where i would need the histogram to be displayed vertically. I figure this would be done with 2d arrays? i havent really got a clue other than needing 80 spaces and *'s in the right spaces lol.
Ive only been coding for a month or so and it being learner based, any help or suggestions would be welcomed
Thank you
Chris