This is your homework, so I won't give you any code solution.
But...you are on the right lines.
All you have to do is work out what is going on, and what you want to happen.
At the moment, you have a loop which runs through each of the numbers in your array and checks if it is less than you entered number. If it is, it stores it in a variable, called "t". After the loop has finished, you print the value of "t". The problem is that if you want to print more than one value (and you do) should the print be outside the loop?
By the way, I don't know if you have met it yet (I'm going to assume you have) but this would be a lot easier to read (and write) if you used a
foreach
loop instead of a
for
- since you don't need to know where you are in teh array, why have a variable to look at where you are?
Without changing any code except the loop (i.e. not fixing your problem at all):
int[] numb = { -9, -8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 8, 9 };
Console.Write("pick a number: ");
int v = int.Parse(Console.ReadLine());
int t = 0;
foreach (int n in numb)
{
if (v > n)
{
t = n;
}
}
Console.Write("Your num under is: " + t);
Console.ReadLine();
See how much easier it is to read?
The other change I made is to add curly brackets around the if statement. While you are getting started, it's a good idea to always use brackets, even if you don't need them - it can make your life a lot easier later when you have to make changes. Trust me on this: I spent hours trying to work out why my code didn't work only to find that if I'd put brackets in it would have been sooooo obvious...:laugh:
So, can you see what you have to do?