Uppercase the vowels

I cannot for the life of me figure out why my program isn't displaying the vowels as uppercase letters. I would appreciate any feedback!

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;
void upperVowel(string&);

int main()
{
  string inputfilename, outputfilename;
  ifstream infile;
  ofstream outfile;
  string words;


  cout << "Please enter the name of the input file" << endl;
  cin >> inputfilename;
  infile.open(inputfilename.c_str());
  cout << "Please enter the name of the output file" << endl;

  cin >> outputfilename;
  outfile.open(outputfilename.c_str());
  outfile << "Input file name: " << inputfilename << endl;
  outfile << "Reformatted Words in the File" << endl;
  infile >> words;
  if (!infile)
    {
      cout << inputfilename << " was not successfully opened" << endl;
    }

else
    {
      while (infile)
        {
          outfile << left << setw(11) << words << endl;
          upperVowel(words);
          infile >> words;
        }
      infile.close();
    }
  outfile.close();
  return 0;
}
  void upperVowel(string& words)
{
  for (int i = 0; i < words.length(); i++)
    {
      if (words[i] == 'a' or words[i] == 'e' or words[i] == 'i' or
          words[i] == 'o' or words[i] == 'u')
        {
          words[i] = toupper(words[i]);
        }
      else
        {
          words[i] = tolower(words[i]);
        }
    }
}
1
2
          outfile << left << setw(11) << words << endl;
          upperVowel(words);


It does convert the vowels to upper case ... but only AFTER you have written the word to file.

Try reversing the two lines above.
Topic archived. No new replies allowed.