[RESOLVED] Array Subscript Errors
Ok, im trying to make a program that takes up to 10 letters entered by the user and if they're lowercase it will make them uppercase, but I have a problem; when I try to run the code below, I get 2 errors (highlighted in red), what's wrong with the way I'm doing this?
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int getCase(int);
int main()
{
const int count = 11;
int array[count], upper;
cout << "Enter 10 uppercase or lowercase letters and I will make them all uppercase.\n";
for (int num = 0; num < count; num++)
{
cin >> array[num];
}
for (int num = 0; num < count; num++)
{
upper[num] = getCase(array[num]);
}
system("CLS");
cout << "Before: ";
for (int num = 0; num < count; num++)
{
cout << static_cast<char>(array[num]);
}
cout << "\nAfter: ";
for (int num = 0; num < count; num++)
{
cout << static_cast<char>(upper[num]);
}
cout << "\n\n";
system("PAUSE");
return 0;
}
int getCase(int low)
{
int test = low, upper;
if (test > 97 && test < 122)
{
upper = test - 32;
}
else
{
upper = low;
}
return upper;
}
In function 'int main()':
19. error: invalid types 'int[int]' for array subscript
30. error: invalid types 'int[int]' for array subscript
||=== Build finished: 2 errors, 0 warnings ===|
[/CODE]
Re: Array Subscript Errors
array isn't an array and even if it was this
Code:
for (int num = 0; num <= count; num++)
would probably also be wrong (index out of bounds).
Re: Array Subscript Errors
Quote:
Originally Posted by
S_M_A
array isn't an array and even if it was this
Code:
for (int num = 0; num <= count; num++)
would probably also be wrong (index out of bounds).
how is the index out of bounds?
Re: Array Subscript Errors
Quote:
Originally Posted by
iiSoMeGuY 7x
how is the index out of bounds?
Declare an array first, and then use it in your program. Once you do that, we'll let you know if and why the index is out of bounds.
Regards,
Paul McKenzie
Re: Array Subscript Errors
Quote:
Originally Posted by
iiSoMeGuY 7x
how is the index out of bounds?
There is no array in the code you posted.
Re: Array Subscript Errors
Well, it looks like you half corrected the code. You only declare one array, but are accessing the variables as if they are both arrays.
Viggy