Creating a program using a vector?

Feb 27, 2019 at 8:45pm
Here is what I have to do:
Read some text into a vector, storing each word in the input as an element in the vector. Transform each word into uppercase letters. Print the trans- formed elements from the vector, printing eight words to a line.

Here is what I have so far. But I cannot get the program to stop. I am trying to get the program to terminate after a user inputs DONE.

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
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cctype>
using std::cin;
using std::cout;
using std::endl;
using std::istringstream;
using std::string;
using std::vector;

using namespace std;

int main()
{
    string s;
    vector<string>v;
    
    cout << "Please enter amount needed for string: ";
    int amount;
    
    cin >> amount;
    
    for(int i = 0; i < amount; i++)
    while (true)
    {
        cin >> s;
        if (s == "DONE") break;
        v.push_back(s);
    }
    for(int i = 0; i < v.size(); ++i)
    {
        for(int j = 0; j < v[i].size(); ++j)
        {
            if(islower(v[i][j]))
            {
                v[i][j] = toupper(v[i][j]);
            }
        }
    }
    
    for(int i = 0; i < v.size(); ++i)
    {
        cout << v[i] << "\n";
    }
    return 0;
}
Feb 27, 2019 at 9:23pm
it works, its just not reading s the way you think it should, try getline instead. I don't have time to look right now, you can fix it with stream commands too; there are several posts on it here, or I will try to get back to it in a couple hours.
Feb 28, 2019 at 4:14am
jonnin,

Thank you for your help. I have removed the for loop before my while loop. It's still not doing what I need it to do. Do you have time to look at it now?
Feb 28, 2019 at 7:47pm
More input.
I took the offending for loop off and it stops on DONE now.
what does it not do that you think it should?
Last edited on Feb 28, 2019 at 7:51pm
Topic archived. No new replies allowed.