CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jan 2011
    Location
    Orange County, CA
    Posts
    82

    [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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured