Input a string and change lower case vowels to upper case

I need to change the vowels to uppercase. But dont know how to do it with only vowels..

Example Input: Hello World
Example Output: HEllO WOrld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>
#include <string>
using namespace std;
int main()
{
    int i;
    char a;
    char sequence[100];
    cout << "Nedir ";
    
    for (i = 0; i < 100; i++)
    {
    cin >> sequence[a];
    cout << static_cast<char>(toupper(sequence[a]));
    }  
    system("pause");
    return 0;    
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
#include <cctype>

bool is_vowel( char c )
{
    // use a simplistic definition of vowel
    // and assume that the language is English or a dialect of English
    static std::string vowels = "aeiouAEIOU" ;

    // http://en.cppreference.com/w/cpp/string/basic_string/find (4)
    return vowels.find(c) != std::string::npos ;
}

int main()
{
    // Input a string
    std::string str ;
    std::cout << " enter a string: " ;

    // http://en.cppreference.com/w/cpp/string/basic_string/getline
    std::getline( std::cin, str ) ;
    std::cout << str << '\n' ;

    // change lower case vowels to upper case
    // http://www.stroustrup.com/C++11FAQ.html#for
    for( char& c : str ) if( is_vowel(c) ) c = std::toupper(c) ;

    std::cout << "modified string: " << str << '\n' ;
}

http://coliru.stacked-crooked.com/a/20b84db1c74aa6b7
Topic archived. No new replies allowed.