Я пытаюсь убедиться, что пользователь вводит значение в диапазоне от 1 до 20, но пришла эта ошибка компиляции, когда я пытался скомпилировать мой код:ошибка компилятора при сравнении указателя и целого числа
error: ISO C++ forbids comparison between pointer and integer
Вот мой код:
#include <iostream>
using namespace std;
const int SIZE=20;
void bubbleSort(int numbers[], int SIZE);
int main()
{
int numbers[SIZE]= {26, 45, 56, 12, 78, 74, 39, 22, 5, 90, 87, 32, 28, 11, 93, 62, 79, 53, 22, 51};
int value=0;
bool found;
cout << "Today we are going to be searching for values." << endl;
cout << "These are the values you have to choose from" << endl;
for (int i=0; i<SIZE; i++)
cout << numbers[i]<<"; ";
cout << "What value would you like to search for?" << endl;
cin >> value;
do
{
cout << "Make sure to enter a value that's in the list." << endl;
cin >> value;
found=false;
for (int i=0; i<SIZE; i++)
{
if (value==numbers[i])
{
found=true;
break;
}
}
if (!found)
cout << "Enter a valid value !" << endl;
}
while (!found);
bubbleSort(numbers, SIZE);
return 0;
}
void bubbleSort (int numbers[], int SIZE)
{
int maxElement=0;
int index=0;
cout << "Original order:" << endl;
cout << numbers << endl;
for(maxElement=SIZE-1; maxElement>=0; maxElement--)
{
for(index=0; index<=maxElement-1; index++)
{
if(numbers[index]>numbers[index+1])
{
swap(numbers[index], numbers[index+1]);
}
}
}
}
void swap(int &a, int &b)
{
int temp;
temp=a;
a=b;
b=temp;
cout << "Bubble Sorted:" << a << b << endl;
}
У вас есть вопросы? – juanchopanza
'while (value! = Numbers)' бессмысленна ерунда. Что вы пытаетесь с этим сделать? Кроме того, 'cout << numbers' не делает то, что вы, кажется, думаете, что он делает (он не печатает содержимое массива' numbers'). –
Можете ли вы объяснить, как вы пришли к выводу, что сравнение 'value! = Numbers' будет проверять, находится ли' value' от 1 до 20? –