2013-01-31 35 views
-4

我需要幫助編寫一個代碼,作爲用戶輸入50到150之間的10個數字而不重複相同的數字。這將是一個循環程序。這是我到目前爲止有:C#用戶輸入隨機數

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace IP3_Program 
{ 
    class Program 
    { 
     static void Main() 
     { 
      int total = 0; 
      string inValue; 
      int [] number = new int[10]; 
      for (int i = 0; i < number.Length; i++) 
      { 
       Console.Write("Enter number{0}: ", i + 1); 
       inValue = Console.ReadLine(); 
       number[i] = Convert.ToInt32(inValue); 
      }    
     } 
    } 
} 
+3

什麼是你的問題? –

+1

目前看起來沒問題。你有什麼需要幫助的? –

+0

你想看看[if](http://msdn.microsoft.com/en-us/library/5011f09h(VS.80).aspx) – Default

回答

1
var numbers = new List<int>(); 
while (numbers.Count != 10) 
{ 
    // get number from user 

    if (numbers.Contains(newNumber) || newNumber < 50 || newNumber > 150) 
    { 
     // reject the number 
     // you'd probably want to display a message here 
     // alerting the user another input in needed 
    } 
    else 
    { 
     numbers.Add(newNumber); 
    } 
} 
+0

需要介於'50'和'150'之間 – Default

+0

@默認10個數字在50到150之間 –

+0

。那麼你的代碼如何驗證'49'? – Default