2014-01-12 31 views
2

我正在使用Microsoft Visual Studio 2010和C#。這是一個函數,在我的控制檯程序的其他地方被稱爲窗體,但我似乎無法獲得輸入數組ipoints錯誤1無法使用[]將索引應用於'int'類型的表達式

static void GetPoints(int ipoints, string srestaurant) 
{ 
    int index = 0; 
    int iinput; 
    for (index = 0; index < 5; index++) 
    { 
     Console.Write("please enter how many points " + srestaurant[index] + " got : "); 
     iinput = Convert.ToInt32(Console.ReadLine()); 

     while (iinput < 0 && iinput > 20) 
     { 
      Console.Write("please enter how many points " + srestaurant[index] + " got : "); 
      iinput = Convert.ToInt32(Console.ReadLine()); 
     } 
     ipoints[index] = iinput; 
    } 
} 

回答

3

您需要將ipoints聲明爲int數組,而不僅僅是int。

更改int ipointsint[] ipoints

+0

感謝幫助了很多,感謝您的快速響應 – blobbymatt

2

你試圖使用intint[]陣列。

這裏:

static void GetPoints(int ipoints, string srestaurant) 
//     ^^^^^^ not an array 

你在這裏做:

ipoints[index] = iinput; 
//  ^^^^^^^ its not an array 

要麼使它成爲一個陣列,或重新考慮你想要做什麼。

相關問題