How to retrieve original output

Hello guys,

What should i do if i want the original input to be written out.
Example: User inputs ThRee. So output should be like:

ThRee
ThRee, ThRee
ThRee, ThRee, ThRee

and not:

three
three, three
three, three, three


I need to have transform alghorithm so i can compare input through map.

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
  #include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <map>
  
using namespace std;
  
int main () {
    map<string,int> m = {{"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
                        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}};
      
    string input;
    while (true) {
        cout << "Enter number from 0-9 with word:" << endl;
        getline(cin, input);
        transform(input.begin(), input.end(), input.begin(), ::tolower);
        if (m.find(input) == m.end()) {
            cout << "Wrong entry!" << endl;
        } else break;
    }
      
    for (int i = 1; i <= m[input]; i++) {
        for (int j = 1; j <= i; j++) {
            cout << input;
            if (j != i) cout << ", ";
        }
        cout << endl;
    }
      
    cin.get();
    return EXIT_SUCCESS;
}
Last edited on
It sounds like you want to save another piece of information on top of what you have. This requires another variable. So after you take the users input, copy it to another string and have at it.
Topic archived. No new replies allowed.