Input a string into an array and output the array string in uppercase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Newbie318
    New Member
    • Oct 2011
    • 4

    Input a string into an array and output the array string in uppercase

    User inputs a string and the program outputs the string in uppercase letters.(Use Character array to store the string) This is what I came up with. I'm new to C++ and any help would be great.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
        int i;
        char a;
        char sequence[100];
        cout << "Enter a string of characters to convert to uppercase: ";
        
        for (i = 0; i < 100; i++)
        {
        cin >> sequence[a];
        cout << static_cast<char>(toupper(sequence[a]));
        }  
        system("pause");
        return 0;    
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Using cin >> sequence[i] will be better. sequence[a] means nothing since the variable a is never initialized.

    Also, you do not need the static_cast.

    Comment

    Working...