這是我代碼標識「N」是未定義
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
int array[100], beg, mid, end, i, num;
cout << "Enter the value of an array" << endl;
cin >> n;
cout << "Enter the values in sorted order (asc or desc)" << endl;
for (i = 0; i < n; i++)
{
cin >> array[i];
}
beg = 0;
end = n - 1;
cout << "Enter the value to searched in an array" << endl;
cin >> num;
while (beg <= end)
{
mid = (beg + end)/2;
if (array[mid] == num)
{
cout << "Item found at this position" << (mid + 1);
exit(0);
}
else if (num > array[mid])
{
beg = mid + 1;
}
else if (num < array[mid])
end = mid - 1;
}
cout << "Number not found." << endl;
return 0;
}
我不是能找到什麼是我的錯誤。 它總是顯示
標識 'N' 是未定義 'N':未聲明的標識符
請任何人給的建議我。提前致謝。
declare n。像int n。在cin >> n; –
難道你不覺得你需要像'beg,mid,end,i,num'那樣將'n'聲明爲int嗎?我的意思是這個錯誤是非常確定的。 – iqstatic
將n聲明爲int – Abi