TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Blankenburg
NA
18
12k
C# user entered value in array compare another entered value
Aug 6 2013 11:49 AM
Hello,
I am new to learning C# and am self teaching myself, this is not for homework but I want to be able to understand this before I move on in my learning/studies.
Here is my task:
Ask the user to enter 10 numbers and store these in a one dimensional array. Get one additional number from the user and then search the array to see if any of the elements is equal to this additional number. If you find it, display a message that you did and if not display another one that it could not be found.
Here is what I have thus far:
namespace CH7Challenge1
{
class Program
{
static void Main(string[] args)
/*
* Ask the user to enter 10 numbers and store these in a one dimensional array.
* Get one additional number from the user and then search the array to see if any of the elements is equal to this additional number.
* If you find it, display a message that you did and if not display another one that it could not be found.
* */
{
int[] myNums;
myNums = new int[10];
int oneNum;
//Get the ten numbers from the user
Console.WriteLine("Please enter 10 numbers: ");
for (int i = 0; i < 10; i++)
{
Console.Write("Number {0}: ", i + 1);
myNums[i] = int.Parse(Console.ReadLine());
}
//get one additonal number from user
Console.WriteLine("please enter one more number:");
oneNum = int.Parse(Console.ReadLine());
My thought next was to just use an if statement like:
if(myNums[i]==oneNum)
{
Console.WriteLine("Your single number matches a number in the array");
}
else
Console.WriteLine("No match");
However this does not work because i cannot use the user entered value stored in [i] outside of the loop...so I am kind of stumped on how to make this work based on my knowledge thus far.
I appreciate any help from anyone.
Reply
Answers (
3
)
c# palindrome program
add new rows on sum output