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.
|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
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:
#include <iostream>
usingnamespace 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;
}
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;
}