Error: Requires Array or Pointer Type

I am writing a program and the errors are all for the lines in which I place a variable in the brackets of i (lines 22, 30, 37, 44) They say that subscript requires array or pointer type and that expression must have the pointer-to-object type. How can I fix this? My program is below. And yes, I have indentation just pasting it in removed it.

#include <iostream>
using namespace std;

int main(){
const int MAX = 25;
int data[MAX];
int count = 0;
int input;

do{
cout << "Enter a number (-1 to stop): ";
cin >> input;
if (input != -1 && input >= 0){
data[count ++] = input;
}
if (input < -1){
cout << "Invalid input. This will not be included in your values." << endl;
}
} while (input != -1 && count < MAX);

for(int i = 0; i < count; i++){
cout << input[i] << ', ';
}
cout << endl;

int output[25];
int count2 = 1;
int duplicate = 0;

output[0] = input[0];

for(int i=0; i<count; i++){
duplicate = 0;

for(int j=0; j<count2; j++){

if(input[i] == output[j]){
duplicate = 1;
}
}
if(duplicate == 1){
continue;
}
output[count2] = input[i];
count2++;
}

for(int i = 0; i < count2; i++){
cout << "The unique numbers you entered were: " << output[i] << ' ';
}


cout<< "You entered " << count << " numbers, " << count2 << " unique." << endl;
cout << "Have a nice day!" << endl;

system("pause");
return 0;
}
Last edited on
Why are you using input as if it was an array, when it's just a single int?
Last edited on
I was trying to find a way to print out the input and to use it when comparing to output so that is what I tried (couldn't really follow my programming book). I tried just printing input but it only prints -1 since that is what is entered in the end. Is there a way to print it so each value gets printed?
But shouldn't you use data[] for that? Looks like you forgot why you used that variable in the first place :D
Yeah apparently I did! Thanks so much for your help :)
Topic archived. No new replies allowed.