所以即時通訊對C++來說仍然很新穎,並且現在已經在執行一段程序。我認爲我正在慢慢獲得它,但不斷收到錯誤「智能感知:'*'的操作數必須是指針。」在第36行第10列。我需要做些什麼來解決這個錯誤?我就要去其他的功能,因爲我完成了額外的函數聲明每一個難過使用指針調用函數時出現錯誤
// This program will take input from the user and calculate the
// average, median, and mode of the number of movies students see in a month.
#include <iostream>
using namespace std;
// Function prototypes
double median(int *, int);
int mode(int *, int);
int *makeArray(int);
void getMovieData(int *, int);
void selectionSort(int[], int);
double average(int *, int);
// variables
int surveyed;
int main()
{
cout << "This program will give the average, median, and mode of the number of movies students see in a month" << endl;
cout << "How many students were surveyed?" << endl;
cin >> surveyed;
int *array = new int[surveyed];
for (int i = 0; i < surveyed; ++i)
{
cout << "How many movies did student " << i + 1 << " see?" << endl;
cin >> array[i];
}
median(*array[surveyed], surveyed);
}
double median(int *array[], int num)
{
if (num % 2 != 0)
{
int temp = ((num + 1)/2) - 1;
cout << "The median of the number of movies seen by the students is " << array[temp] << endl;
}
else
{
cout << "The median of the number of movies seen by the students is " << array[(num/2) - 1] << " and " << array[num/2] << endl;
}
}
所以'array'是int'的'數組。在第36行中,你可以執行'* array [surveyed]'。這在調查的索引處訪問陣列數組(在這裏是錯誤的命名)。這給出了一個int,然後*嘗試去引用。 int是一個原始類型,它不是一個指針,所以不能被去引用。 – 2015-02-11 19:34:55
喵,將'array [surveyed]'改爲'array'。 – WhozCraig 2015-02-11 19:37:35
'所以即時通訊對C++來說還是個新鮮事物,並且已經做了一段時間的程序了'所以你說你找不到幾十萬個例子中的一個例子,向你展示傳遞一個數組的正確方法,如何正確聲明功能? – PaulMcKenzie 2015-02-11 19:37:39