write a console application that request 10 numbers from the user as individual inputs
each number must be between 10 and 10 inclusive
compare each number to the last number and determine if it is a duplicate if so ask the user for another number
output each number to the screen once all conditions are met
end the program after the loop by requesting the user to hit enter to end the program

Sibeesh VenuRank #27 · 42.9K reputationPosted Nov 9, 2014, 6:51 PM EST
MahaRank #2,573 · 543 reputationPosted Nov 12, 2014, 12:08 AM EST
using System;
class Program
{
static void Main(string[] args)
{
int[] num = new int[10];
int i;
for (i = 0; i < num.Length; i++)
{
Console.Write("\nInput a number ");
int n = int.Parse(Console.ReadLine());
while (true)
{
if (num[0] != n && num[1] != n && num[2] != n && num[3] != n && num[4] != n && num[5] != n && num[6] != n && num[7] != n && num[8] != n && num[9] != n)
{
num[i] = n;
Console.WriteLine("\n------------------- num[{0}] = {1} -----", i, n);
break;
}
else
{
Console.WriteLine("\nNumber is " + n + " already exist. Try again");
Console.Write("\nInput a number ");
n = int.Parse(Console.ReadLine());
}
}
}
Console.WriteLine("\nEnd of the program");
Console.ReadKey();
}
}
VulpesRank #55 · 29.2K reputationPosted Nov 12, 2014, 12:53 AM EST
When it says each number must be between 10 and 10 inclusive, I assume it means that it must be between 1 and 10 inclusive.
Also it says compare each number to the last number and determine if it's a duplicate. I assume this just means the last number entered and not any previously entered numbers.
Your solution, Maha, doesn't address the first point and I think you've assumed that it shouldn't duplicate ANY of the previously entered numbers which may or may not be correct.
What I'd have done is this:
MahaRank #2,573 · 543 reputationPosted Nov 12, 2014, 1:03 AM EST