Write 10positive numbers and check...but got error

Hello, I'm new here..I'm trying to write a program that will do the following:
Write 10 numbers and check if the number is positive and if its positive user goes forward to entering the next number, if it's not user has to try again.
I think this is how it should be but I get an error.

1
2
|12|error: invalid types `int[int]' for array subscript|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===| 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  #include <iostream>

using namespace std;

int main()
{
    int numbers, i=0;
    cout<<"Enter 10 positive numbers"<<endl;
    for(i=0;i<10;i++)
    {
        cin>>numbers;
        if(numbers[i]<0)
        {
            i=i--;
            cout<<"Error, the number you entered was negative, please try again!" <<endl;
        }
    }


    return 0;
}




Thanks
Last edited on
|12|error: invalid types `int[int]' for array subscript


line 12 - you're trying to use numbers as an array, but you've declared it on line 7 as a regular int variable. You can't use subscripts on a regular int, that's what the error message is saying.

on line 14 you can use i--; that will decrement i

edit: if numbers is supposed to be an array, line 11 will have to change to have a subscript
Last edited on
Thank you, I fixed it thanks to you and now it works good!
Just one more thing, do you know how I can make if n is > 10 to write an error and to make the user write n untill the number is 10 or less than 10?
Here's the current program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include <iostream>

using namespace std;

int main()
{
    int numbers[10], i=0, n;
    cout<<"Enter the amount of positive numbers you would like to write" <<endl;
    cin>>n;
    cout<<"Enter " <<n<< " positive numbers"<<endl;
    for(i=0;i<n;i++)
    {
        cin>>numbers[i];
        if(numbers[i]<0)
        {
            i--;
            cout<<"Error, the number you entered was negative, please try again!" <<endl;
        }
    }
    system("PAUSE");
    return 0;
}
You could do something like this...

1
2
3
4
5
6
7
    cout<<"Enter the number of positive numbers (up to 10) you would like to enter" <<endl;
    cin>>n;
    while (n>10)
    {
        cout << "Sorry, I can only remember up to 10 numbers at a time, please re-enter: ";
        cin >> n;
    }
Topic archived. No new replies allowed.