|
-
May 12th, 2011, 11:56 PM
#1
[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]
Last edited by iiSoMeGuY 7x; May 14th, 2011 at 03:58 PM.
Reason: Update Code
-
May 13th, 2011, 02:01 AM
#2
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).
-
May 13th, 2011, 07:34 PM
#3
Re: Array Subscript Errors
 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?
-
May 13th, 2011, 07:40 PM
#4
Re: Array Subscript Errors
 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
-
May 13th, 2011, 09:50 PM
#5
Re: Array Subscript Errors
 Originally Posted by iiSoMeGuY 7x
how is the index out of bounds?
There is no array in the code you posted.
-
May 16th, 2011, 11:27 AM
#6
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|