How to display the all results of the user inputs at the end of the program

Hello I need help making this program display all the inputs the user made. I know its some type of loop but can not figure out what loop to use. I have been struggling with this problem. This problem relates to an issue with another program im making but cant seem to figure out.

I want the program to output all the strings that the user inputed even the
the ones that he input after he says yes to the programm

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
  #include <iostream>             // provides:  cout, cin
#include <iomanip>              // provides:  setw
#include <limits>
// setting up the environment
  using namespace std;


bool run;
string first, second, third, inputYN;
int count = 1;
int main()
 {
 run = true;
 while (run == true){
 cout << "1. please enter a string: ";
 cin >> first;
   cout << " 2. please enter a string: ";
  cin >> second;
   cout << "3. please enter a string: "; 
  cin >> third; 
  cout << "\n\n\n Doy wish to enter more string string [y] or [n] ?: ";
  cin >> inputYN;
  if (inputYN == "Y" || inputYN == "y"||inputYN == "yes"|| inputYN == "Yes" ||    inputYN == "YES"  )
{ 	run = true;
	count++;

    }

 else if (inputYN == "N" ||inputYN == "n" ||inputYN == "no" || inputYN == "No" ||inputYN == "NO" )
 {
    run = false;
 // I want to display all the strings inputed. i know it a loop but i have  no idea 
 // what loop to use
for (int i = 1; i<=count ; i++){

 cout << first << "\n" << second << "\n" << third <<endl;
}


 }
  else 
 {
 cout << "****Error: Please enter Yes or No!\n\n";
 run = true;

 }

 }

 system("pause");
 return 0;
}
Last edited on
Loop over what? You do overwrite the three strings every time the outer while loop repeats, so effectively you have stored only the values of the last iteration.

If you want to keep more than one set of words, then you have to store them all somewhere. std::vector is one candidate.
@keskiverto i want it to loop over the program but i dont want to overwrite the strings like you said i will look into the vectors to see if i can change it.
Topic archived. No new replies allowed.