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
#include <iostream> // provides: cout, cin
#include <iomanip> // provides: setw
#include <limits>
// setting up the environment
usingnamespace 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++;
}
elseif (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;
}
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.